#include <iostream>
using namespace std;
int main() {
int n, h, m, i, j, p;
cin >> n;
cin >> h >> m;
int t[n];
int arr[p];
for (i = 0; i < n; i++) {
cin >> t[i];
}
for (i = 0; i < n + 1; i++) {
cin >> p;
if (p == 0) {
break;
}
int minutes = m + t[p - 1];
int hours = h;
if (minutes >= 60)
{
minutes=minutes- 60;
hours++;
}
if (hours >= 24)
{
hours=hours- 24;
}
cout << hours << ":";
if (minutes < 10)
{
cout << "0";
}
cout << minutes << endl;
}
}