#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e6 + 10;
int t, n, m, k, l, r, op, x, y, d;
int f[N];
bool flag;
int months[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isLeapYear(int y) {
return (y % 4 == 0 && y % 100 != 0) && (y % 400 == 0);
}
struct date {
int _y, _m, _d;
date(int y, int m, int d): _y(y), _m(m), _d(d) {};
date next() {
int d = _d + 1;
int m = _m;
int y = _y;
int mD = months[m];
if (m == 2 && isLeapYear(y))mD++;
if (d <= mD) {
return date(y, m, d);
}
d = 1;
m++;
if (m == 13) {
y++;
m = 1;
}
return date(y,m,d);
}
void print() {
printf("%04d-%02d-%02d\n", _y, _m, _d);
}
};
void solve() {
cin >> t;
while (t--) {
cin >> y >> m >> d;
date dt(y, m, d);
dt.next().print();
}
}
int main() {
solve();
return 0;
}