#define I inline #define fi first #define se second #define pb push_back #define MP make_pair #define PII pair<int , int> #define PSL pair<string , long long> #define PLL pair<long long , long long> #define all(x) (x).begin() , (x).end() #define copy(a , b) memcpy(a , b , sizeof(b)) #define clean(a , b) memset(a , b , sizeof(a)) #define rep(i , l , r) for (int i = (l); i <= (r); i ++) #define per(i , r , l) for (int i = (r); i >= (l); i --) #define PE(i , x) for(int i = head[x]; i; i = edge[i].last) #define DEBUG(x) std :: cerr << #x << '=' << x << std :: endl
typedeflonglong ll; typedefunsignedlonglong ull;
template <classT> inlinevoidread(T &x){ char c = getchar(), f = 0; x = 0; while (!isdigit(c)) f = (c == '-'), c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); x = f ? -x : x; }
usingnamespacestd;
constint N = 10000 + 5; constint M = 100000 + 5; constint HA = 998244353;
ll check(int x){ //计算当前年份1月1日对应的天数 ll day = 0; day += 1ll * (x + 4712) * 365; if(x > 1582) day -= 10; day += 1ll * (x + 4712 + 3) / 4; if(x >= 1600){ x -= 1601; day += x / 400; day -= x / 100; } return day; }
voidget_day(){ //暴力模拟天数 d ++; if(y == 1582 && m == 10 && d == 5) d += 10; if(d > days[m] + (check_RUN(y) && m == 2)) m ++ , d = 1; if(m > 12) y ++ , m = 1 , d = 1; }
voidsolve(){ int n; read(n); m = 1 , d = 1; ll l = -4712 , r = 1e9 + 10; while(l <= r){ ll mid = (l + r) >> 1; if(check(mid) > n){ r = mid - 1; } else l = mid + 1 , y = mid; } n -= check(y); if(y <= 0) y -= 1; rep(i , 1 , n) { get_day(); } if(y <= 0) printf("%lld %lld %lld BC\n" , d , m , -y); elseprintf("%lld %lld %lld \n" , d , m , y); }
intmain(){ #ifdef LOCAL freopen("try.in" , "r" , stdin); freopen("try1.out" , "w" , stdout); #endif int t; read(t); while(t --) solve();