#include "stdio.h" #include "string.h" int main() { int i,j,n,a1,b1,c1,d1,e1,f1,check; char s[25],end[3]; char a[5],b[5],c[5],d[3],e[3],f[3]; scanf("%d",&n); while(n--) { scanf("%s",s); // char sign[] = "am"; check=0; a1=b1=c1=d1=e1=f1=0;i=0; while(s[i]!='/') a[a1++]=s[i++]; i++; while(s[i]!='/') b[b1++]=s[i++]; i++; while(s[i]!='-') c[c1++]=s[i++]; i++; while(s[i]!=':') d[d1++]=s[i++]; i++; while(s[i]!=':') e[e1++]=s[i++]; i++; while(s[i]!='/0') f[f1++]=s[i++]; if(d[0]-'0'==0&&d[1]-'0'==0) {d[0]='1';d[1]='2';} else if((d[0]-'0'==1&&d[1]-'0'>=2)||d[0]-'0'==2) { check=1;} /* if(d[0]-'0'<=1&&d[1]-'0'<=1) end[0]='a'; else end[0]='p'; end[1]='m'; */ if(d[0]-'0'==2&&d[1]-'0'==4) {d[0]='1';d[1]='2';check=0;} // if(d[0]-'0'==0&&d[1]-'0'==0) {d[0]='1';d[1]='2';} if(d[0]-'0'==1&&d[1]-'0'>=3) { d[0]='0';d[1]=d[1]-2;} if(d[0]-'0'==2) { if(d[1]-'0'-2>=0){ d[0]='1'; d[1]=d[1]-2;} else {d[0]='0';d[1]=d[1]+8;}} printf("%c%c/%c%c/%c%c%c%c",b[0],b[1],c[0],c[1],a[0],a[1],a[2],a[3]); printf("-%c%c:%c%c:%c%c",d[0],d[1],e[0],e[1],f[0],f[1]); if(check==0) printf("am/n"); else printf("pm/n"); } // system("pause"); return 0; }