#include <iostream>
using namespace std;

int mo1[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int mo2[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main() {
    int _;
    cin>>_;
    while(_--)
    {
        int y,m,d;
        cin>>y>>m>>d;
        if((y%4==0&&y%100!=0) || (y%400==0))
        {
            if(d==mo1[m])
            {
                m++;
                d=1;
                 if(m==12)
                {
                    y++;
                    m=1;
                }
            }
            else d++;
        }
        else {
             if(d==mo2[m])
            {
                m++;
                d=1;
                if(m==12)
                {
                    y++;
                    m=1;
                }
            }
            else d++;

        }
        cout<<y;
        if(m<10)
        {
            cout<<"-0"<<m;
            if(d<10)
            {
                cout<<"-0"<<d<<endl;
            }
            else {
            {
                cout<<"-"<<d<<endl;
            }
            }
        }
        else {
            cout<<"-"<<m;
            if(d<10)
            {
                cout<<"-0"<<d<<endl;
            }
            else {
            {
                cout<<"-"<<d<<endl;
            }
            }
        }




    }
}
// 64 位输出请用 printf("%lld")