#include <bits/stdc++.h>
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
using namespace std;
typedef long long LL;


LL next(char *&s) {
	LL ret=0;
	for (++s;*s;s++) {
		if (*s=='.'||*s==':') break;
		ret=ret*10+*s-48;
	}
	return ret;
}
LL cl(string &ss) {
	char ts[100],*s=ts;
	strcpy(s,ss.c_str());
	int n=ss.size();

	LL fu=s[0]=='-'?-1:1;
	if (s[0]!='-'&&s[0]!='+') s--;
	LL a=next(s),b=next(s);
	return fu*(a*60+b);
}
void print(LL ans) {
	LL b=ans%60,a=ans/60;
	if (b<0) b+=60,a--;
	printf("%lld:%02lld\n",a,b);
}
int main() {
	string s;
	for (LL ans=0;cin>>s;) {
		if (s[0]=='#') {
			print(ans);
			break;
		}
		if (s[0]=='$') {
			print(ans);
			ans=0;
			continue;
		}

		ans+=cl(s);
	}
	return 0;
}

/*
	1. 要注意static变量的初始化。
	2. 返回WA时，不一定是细节出错，也有可能是数组越界之类的问题。
*/