Problem:
Millennium
A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1.  Each year consists of 10 months, from month 1 through month 10, and starts from a
big month
.  A common year shall start with a big month, followed by
small months
and big months one after another.  Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one.  A big month consists of 20 days and a small month consists of 19 days.  However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month."
Many years have passed since the calendar started to be used.  For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery.  Write a program that helps people calculate the number of days since their birthdate to the millennium day.
Input
The input is formatted as follows.
n
Y
1
M
1
D
1
Y
2
M
2
D
2
...
Y
n
M
n
D
n
Here, the first line gives the number of datasets as a positive integer
n
, which is less than or equal to 100.  It is followed by
n
datasets.  Each dataset is formatted in a line and gives three positive integers,
Y
i
(< 1000),
M
i
(≤ 10), and
D
i
(≤ 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar.  These three numbers are separated by a space.
Output
For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive.  Output lines should not contain any character other than this number.
Sample Input
8
1 1 1
344 3 1
696 5 1
182 9 5
998 8 7
344 2 19
696 4 19
999 10 20
Output for the Sample Input
196470
128976
59710
160715
252
128977
59712
1

Submitted solutions:

code_snippet: #line 1 "speedrun.cpp"
#include <bits/stdc++.h>
#line 1 "/home/ardririy/repos/cp-libs/libraries-cpp/input.hpp"


#line 6 "/home/ardririy/repos/cp-libs/libraries-cpp/input.hpp"
using namespace std;
vector<long long> i64_vec_IN(int n) {vector<long long> res(n); for(int i=0; i<n; i++) { cin >> res[i]; } return res; }
vector<string> str_vec_IN(int n) { vector<string> res(n); for(int i=0; i<n; i++) { cin >> res[i]; } return res; }
vector<vector<int>> graph_IN(int n, int m) { vector<vector<int>> g(n); int u, v; for(int i=0; i<m; i++) { cin >> u >> v; u--; v--; g[u].emplace_back(v); g[v].emplace_back(u); } return g; }
vector<vector<pair<int, long long>>> weighted_graph_IN(int n, int m) { vector<vector<pair<int, long long>>> g(n); int u, v; long long w; for(int i=0; i<m; i++) { cin >> u >> v >> w; u--; v--; g[u].push_back({v, w}); g[v].push_back({u, w}); } return g; }


#line 3 "speedrun.cpp"

using namespace std;
//using namespace atcoder;

#ifdef ADRY
#include <dbg.h>
#else
// DO NOTHING
#define dbg(...)
#endif


#define all(v) v.begin(),v.end()
#define resort(v) sort(v.rbegin(),v.rend())
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
using vp=vector<pair<ll, ll>>;
using djks=priority_queue<P, vp, greater<P>>;

const int inf=1ll<<30;
#define mod10 (ll)1e9+7
#define mod99 (ll)998244353
const double PI = acos(-1);

#define rep(i,n) for (ll i=0;i<(n);++i)
#define per(i,n) for(ll i=(n)-1;i>=0;--i)
#define rep2(i,a,n) for (ll i=(a);i<(n);++i)
#define per2(i,a,n) for (ll i=(n)-1;i>=(a);--i)


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

ll dx[] = {1, 0, -1, 0, -1, 1, -1, 1};
ll dy[] = {0, 1, 0, -1, -1, 1, 1, -1};

int solve() {
    int y, m, d; cin >> y >> m >> d;

    int cy = y;
    int cm = m;
    int cd = d;
    int ans = 0;
    while(true) {
        ans++;

        cd++;
        if(cy%3==0 || cm%2==1) {
            if(cd==21) cd=1, cm++;
        } else {
            if(cd==20) cd=1, cm++;
        }

        if(cm==11) cm = 1, cy++;
        if(cy==1000) break;
    }
    cout << ans << '\n';

    return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin >> t;
    while(t--)solve();
    //while(!solve());
}
accuracy: 1
time_ms: 20
memory_kb: 3392
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(){
    int n; cin >> n;

    auto next_day = [&](int &y, int &m, int &d) -> void {
        d += 1;
        if(y % 3 == 0){
            if(d > 20){
                m += 1, d = 1;
            }
        }
        else if(m % 2 == 1 and d > 20 or m % 2 == 0 and d > 19){
            m += 1, d = 1;
        }
        if(m > 10){
            y += 1, m = 1;
        }
    };

    auto f = [&](int y, int m, int d) -> int {
        int ret = 0;
        while(y < 1000){
            ++ret;
            next_day(y, m, d);
        }
        return ret;
    };

    for(int i = 0; i < n; ++i){
        int Y, M, D; cin >> Y >> M >> D;
        cout << f(Y, M, D) << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3352
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

int day(int Y, int M) {
    return Y % 3 == 0 ? 20 : M % 2 == 0 ? 19 : 20;
}

int Y = 1000, M = 10, D = 20;
int memo[1010][11][22];

int solve(int y, int m, int d) {
    if (memo[y][m][d] != -1) return memo[y][m][d];
    d++;
    if (d > day(y, m)) {
        d = 1;
        m++;
    }
    if (m > M) {
        m = 1;
        y++;
    }
    if (y == 1000) return 1;
    return solve(y, m, d) + 1;
}

int main() {
    for (int y = 0; y < Y; y++) {
        for (int m = 1; m <= M; m++) {
            for (int d = 1; d <= D; d++) {
                memo[y][m][d] = -1;
            }
        }
    }
    int T;
    cin >> T;
    while (T--) {
        int y, m, d;
        cin >> y >> m >> d;
        cout << solve(y, m, d) << '\n';
    }
}
accuracy: 1
time_ms: 30
memory_kb: 4356
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, a, b) for(ll i = a; i < b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)
constexpr ll inf = 4e18;
struct SetupIO {
    SetupIO() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(30);
    }
} setup_io;
int main(void) {
    int n;
    cin >> n;
    vector<int> y(n), m(n), d(n);
    rep(i, 0, n) {
        cin >> y[i] >> m[i] >> d[i];
        int ans = 0;
        while(y[i] != 1000) {
            ans++;
            d[i]++;
            if(y[i] % 3 == 0) {
                if(d[i] == 21) {
                    d[i] = 1;
                    m[i]++;
                    if(m[i] == 11) {
                        m[i] = 1;
                        y[i]++;
                    }
                }
            } else {
                if(m[i] % 2 == 0) {
                    if(d[i] == 20) {
                        d[i] = 1;
                        m[i]++;
                        if(m[i] == 11) {
                            m[i] = 1;
                            y[i]++;
                        }
                    }
                } else {
                    if(d[i] == 21) {
                        d[i] = 1;
                        m[i]++;
                        if(m[i] == 11) {
                            m[i] = 1;
                            y[i]++;
                        }
                    }
                }
            }
        }
        assert(y[i] == 1000 and m[i] == 1 and d[i] == 1);
        cout << ans << '\n';
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3352
final_rank: 6

code_snippet: #include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
#define all(x) x.begin(), x.end()
template <class A, class B>
inline bool chmin(A &a, const B &b) {
    return b < a && (a = b, true);
}
template <class A, class B>
inline bool chmax(A &a, const B &b) {
    return b > a && (a = b, true);
}

int solve() {
    int y, m, d;
    cin >> y >> m >> d;
    int ans = 0;
    while (y != 1000) {
        ans++;
        int dd = (y % 3 == 0 ? 20 : (m % 2 == 0 ? 19 : 20));
        if (d < dd) {
            d++;
        } else {
            d = 1;
            if (m < 10) {
                m++;
            } else {
                m = 1;
                y++;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

int main() {
    int n;
    cin >> n;
    while (n--) solve();
}
accuracy: 1
time_ms: 20
memory_kb: 3444
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<long long>;
using vvl = vector<vector<long long>>; using vs = vector<string>;
using pl = pair<long long, long long>;
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}
template<class T>using rp_queue=priority_queue<T,vector<T>,greater<T>>;
template <typename T> T gcd(T a, T b) {if (b == 0)return a; else return gcd(b, a % b);}
template <typename T> inline T lcm(T a, T b) {return a /gcd(a, b)*b;}
const ll INF = 1LL << 60;
const ld PI = acos(-1);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec);
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr);
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const pair<T, U> &pa);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec);
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec);
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa);
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp);
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp);
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl);

template <class OStream, class T> OStream &operator<<(OStream &os, const std::vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T, size_t sz> OStream &operator<<(OStream &os, const std::array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
template <class... T> std::istream &operator>>(std::istream &is, std::tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <class OStream, class... T> OStream &operator<<(OStream &os, const std::tuple<T...> &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; }
template <class OStream, class T, class TH> OStream &operator<<(OStream &os, const std::unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T> OStream &operator<<(OStream &os, const std::unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <class OStream, class T, class U> OStream &operator<<(OStream &os, const std::pair<T, U> &pa) { return os << '(' << pa.first << ',' << pa.second << ')'; }
template <class OStream, class TK, class TV> OStream &operator<<(OStream &os, const std::map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <class OStream, class TK, class TV, class TH> OStream &operator<<(OStream &os, const std::unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl
#define dbgif(cond, x) ((cond) ? std::cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << std::endl : std::cerr)
#else
#define dbg(x) ((void)0)
#define dbgif(cond, x) ((void)0)
#endif
void solve();
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  int num_tc = 1;
  //cin >> num_tc;
  rep(tc,num_tc){
    //cout << "Case #" << tc+1 << ": " ;// << endl;
    solve();
  }
}
//見切り発車で実装しては行けない．頭の中でコードが完全に出来上がるまで書き始めるな．
#define si(A) (int)(A).size()
void solve(){
  int N;cin>>N;
  while(N--){
    ll Y,M,D;cin>>Y>>M>>D;
    ll cnt = 0;
    while(true){
      if(Y==1000&&M==1&&D==1)break;
      cnt++;
      D++;
      if(Y%3==0){
        if(D==21)D=1,M++;
        if(M==11)M=1,Y++;
      }else{
        if(M%2==1&&D==21)D=1,M++;
        else if(M%2==0&&D==20)D=1,M++;
        if(M==11)M=1,Y++;
      }
    }
    dbg("OK");
    cout<<cnt<<endl;
  }
}
accuracy: 1
time_ms: 20
memory_kb: 3340
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin>>n;
    vector<vector<int>> days(n,vector<int>(3));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>days[i][j];
        }
    }
    for(int i=0;i<n;i++){
        int count=0;
        while(days[i][0]<1000){
            if(days[i][0]%3==0 || days[i][1]%2==1){
                //大の月
                int pd=days[i][2];
                days[i][2]=(pd+1)%21;
                if(days[i][2]==0) days[i][2]++;

                int pm=days[i][1];
                days[i][1]=(pm+(pd+1)/21)%11;
                if(days[i][1]==0) days[i][1]++;

                days[i][0]+=(pm+(pd+1)/21)/11;
            }
            else if(days[i][1]%2==0){
                //小の月
                int pd=days[i][2];
                days[i][2]=(pd+1)%20;
                if(days[i][2]==0) days[i][2]++;

                int pm=days[i][1];
                days[i][1]=(pm+(pd+1)/20)%11;
                if(days[i][1]==0) days[i][1]++;

                days[i][0]+=(pm+(pd+1)/20)/11;
            }
            count++;
        }
        cout<<count<<endl;
    }
}
accuracy: 1
time_ms: 50
memory_kb: 3396
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
  #include "settings/debug.cpp"
  #define _GLIBCXX_DEBUG
#else
  #define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  map<tuple<int, int, int>, int> mp;
  {
    int y = 1, m = 1, d = 1, idx = 1;
    while (y <= 1000) {
      Debug(y, m, d);
      mp[{ y, m, d }] = idx++;
      d++;
      if (y % 3 != 0 && m % 2 == 0 && d == 20) {
        d = 1, m++;
      }
      else if ((y % 3 == 0 || m % 2 != 0) && d == 21) {
        d = 1, m++;
      }
      if (m == 11) {
        m = 1, y++;
      }
    }
  }
  Debug("done");
  int n;
  cin >> n;
  rep(i, n) {
    int y, m, d;
    cin >> y >> m >> d;
    cout << mp[{ 1000, 1, 1 }] - mp[{ y, m, d }] << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 15652
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    int Y, M, D;
    cin >> Y >> M >> D;
    int ans = 0;
    while(Y != 1000){
      ans++;
      D++;
      if(Y % 3 == 0){
        if(D == 21){
          M += 1;
          D = 1;
        }
      }else{
        if(M % 2 == 0){
          if(D == 20){
            M += 1;
            D = 1;
          }
        }else{
          if(D == 21){
            M += 1;
            D = 1;
          }
        }
      }
      if(M == 11){
        Y += 1;
        M = 1;
      }
    }
    cout << ans << endl;
  }
}
accuracy: 1
time_ms: 20
memory_kb: 3424
final_rank: 14

code_snippet: #include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int y, m, d;
        cin >> y >> m >> d;
        int cnt = 0;
        while (!(y == 1000 && m == 1 && d == 1)) {
            int M;
            if (m % 2 == 1 || y % 3 == 0) {
                M = 20;
            } else {
                M = 19;
            }
            if (d < M) {
                d++;
            } else if (m < 10) {
                m++;
                d = 1;
            } else {
                y++;
                m = 1;
                d = 1;
            }
            cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3084
final_rank: 2

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }

const tuple<int, int, int> millennium = {1000, 1, 1};

tuple<int, int, int> next_day(tuple<int, int, int> &day){
    auto [y, m, d] = day;
    d++;
    if (y % 3 && m % 2 == 0 && d == 20){
        d = 1;
        m++;
    }else if (d == 21){
        d = 1;
        m++;
    }

    if (m == 11){
        m = 1;
        y++;
    }
    return {y, m, d};
}

int solve(tuple<int, int, int> day){
    int ans = 0;
    while (true){
        day = next_day(day);
        ans++;
        if (day == millennium) return ans;
    }
}

int main(){
    int T; cin >> T;
    vc<int> ans;
    while (T--){
        int y, m, d; cin >> y >> m >> d;
        ans.push_back(solve({y, m, d}));
    }
    for (auto x : ans) cout << x << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3208
final_rank: 3

code_snippet: #include<iostream>

using namespace std;

int main(){
    
    int n;
    cin >> n;

    for(int i = 0 ; i < n ; i ++){
        int Y, M, D;
        cin >> Y >> M >> D;
        int totalDays = 0;

        while( Y < 1000 ){

            D ++;
            totalDays++;
            if(Y % 3 != 0){
                if(M % 2 == 0 && D == 20){
                    D = 1;
                    M++;
                }
                else if( M % 2 != 0 && D == 21){
                    D = 1;
                    M ++;
                }   
            }
            else if( Y % 3 == 0){
                if(D == 21){
                    D = 1;
                    M ++;
                }
            }
            if(M == 11){
                M = 1;
                Y ++;
            }

        }

        cout << totalDays << endl;

    }

    return 0;
    
}
accuracy: 1
time_ms: 10
memory_kb: 3080
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
  map<vector<int>,int> Map;
  int now = 0;
  vector<int> today = {1,1,1};
  Map[today] = now;
  while(now <= 200000){
    now++;
    int Y = today[0];
    int M = today[1];
    int D = today[2];
    if(D <= 18) D++;
    else if(D == 19){
      if(Y%3 == 0) D++;
      else if(M%2 == 1) D++;
      else{
        if(M <= 8){
          M++;
          D = 1;
        }
        else{
          Y++;
          M = 1;
          D = 1;
        }
      }
    }
    else{
      if(M <= 9){
        M++;
        D = 1;
      }
      else{
        Y++;
        M = 1;
        D = 1;
      }
    }
    today[0] = Y;
    today[1] = M;
    today[2] = D;
    Map[today] = now;
  }
  int n;
  cin >> n;
  vector<int> theday = {1000,1,1};
  for(int i=0;i<n;i++){
    vector<int> day(3);
    for(int j=0;j<3;j++) cin >> day[j];
    cout << Map[theday]-Map[day] << endl;
  }
}
accuracy: 1
time_ms: 50
memory_kb: 25252
final_rank: 20

code_snippet: #line 2 "template.hpp"
#include <bits/stdc++.h>
using namespace std;
#define square(x) ((x)*(x))
#define endl '\n'
#define debug(val); cerr << #val << ": " << val << endl;

// 型エイリアス
using ll = long long int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using uint = unsigned int;
using T3 = tuple<ll, int, int>;
// 定数
constexpr int INT_INF = 1e9 + 1;
constexpr ll INF = 1LL << 60;
// constexpr ll MOD = (long long)1e9 + 7;
constexpr ll MOD = 998244353;

// 配列での方向
// 上下左右（右から時計回り）
constexpr int dx[4] = { 1, 0, -1, 0 };
constexpr int dy[4] = { 0, 1, 0, -1 };
// 斜め4方向（右上から時計回り）
//constexpr int dx[4] = { 1, 1, -1, -1 };
//constexpr int dy[4] = { -1, 1, 1, -1 };
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void Yes(bool yes)
{
    if (yes) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}

// pii
ostream& operator<<(ostream& os, pii p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
// vector<T>
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    for (const T& val : v)
    {
        os << val << ' ';
    }

    return os;
}
// vector<vector<T>>
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& v)
{
    for (const vector<T>& line : v)
    {
        os << endl;
        for (const T& val : line)
        {
            os << val << ' ';
        }
    }

    return os;
}
// set<T>
template <typename T>
ostream& operator<<(ostream& os, const set<T>& s)
{
    for (auto itr = s.begin(); itr != s.end(); ++itr)
    {
        os << *itr << ' ';
    }
    return os;
}
#line 2 "a.cpp"

int N;

int main(void) {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int y, m, d;
		cin >> y >> m >> d;

		int days = 0;
		while (true) {
			if (y == 1000 && m == 1 && d == 1) break;

			int daysInMonth = 0;
			if (y % 3 == 0) {
				daysInMonth = 20;
			}
			else {
				if (m % 2 == 1) daysInMonth = 20;
				else if (m % 2 == 0) daysInMonth = 19;
			}
			// d
			if (d == daysInMonth) {
				m = (m + 1) % 10;
				d = 0;
			}
			// y
			if (m == 1 && d == 0) {
				y += 1;
			}
			++d;
			++days;
		}
		cout << days << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3440
final_rank: 10

code_snippet: #include "bits/stdc++.h"
using namespace std;
#define reps(i, a, b) for(long long (i) = (a); (i) < (b); ++(i))
#define rep(i, n) for(long long (i) = 0; (i) < (n); ++(i))
#define repr(i, b, a) for(long long (i) = (b); (i) >= (a); --(i))
using ll = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long> >;
using pl = pair<long long, long long>;
using tl = tuple<long long, long long, long long>;
using graph = vector<vector<int> >;
struct Edge{
    int to;
    long long cost;
    Edge(int t, long long c) : to(t), cost(c) {}
    bool operator<(const Edge &a) const{return cost < a.cost;}
    bool operator>(const Edge &a) const{return cost > a.cost;}
};
using wgraph = vector<vector<Edge> >;
constexpr long long INF = numeric_limits<long long>::max() / 8;
constexpr long long dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr long long dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<typename T, typename U> inline bool chmax(T &a, const U& b) {if(a<b){a=b;return true;}return false;}
template<typename T, typename U> inline bool chmin(T &a, const U& b) {if(a>b){a=b;return true;}return false;}
template<typename T, typename U> inline T POW(T x, U n) {T ret=1;while(n>0){if(n&1){ret=ret*x;}if(n>>=1){x=x*x;}}return ret;}
template<typename T, typename U> inline T MOD(T n, U m) {if(n >= 0) {return n % m;} else return (n%m + m)%m;}
template<typename T, typename U, typename V> inline T POWMOD(T x, U n, V m){T ret=1;x%=m;while(n>0){if(n&1)ret=ret*x%m;if(n>>=1){x=x*x%m;}}return ret%m;}
template<typename T, typename U> inline T div_ceil(T a, U b){return (a + b - 1) / b;}
template<typename T> inline long long KETA(T n, long long base = 10){long long ret = 0;while(n){ret++; n /= base;} return ret;}
template<typename T> inline long long popcount(T a){return __builtin_popcount(a);}
template<typename T> inline bool contains(T S, T i){return (S & (T(1) << i)) != 0;}
template<typename T> inline void fin(T a){cout << a << '\n'; exit(0);}
template<typename T> inline long long ub_index(vector<T> &v, T a){return upper_bound(v.begin(), v.end(), a) - v.begin();}
template<typename T> inline long long lb_index(vector<T> &v, T a){return lower_bound(v.begin(), v.end(), a) - v.begin();}
template<typename T> inline long long ika_index(vector<T> &v, T a){return upper_bound(v.begin(), v.end(), a) - v.begin() - 1;}
template<typename T> inline long long miman_index(vector<T> &v, T a){return lower_bound(v.begin(), v.end(), a) - v.begin() - 1;}
template<typename T> inline T SUM(const vector<T> &v){return accumulate(v.begin(), v.end(), (T)0);}
template<typename T> inline T MIN(const vector<T> &v){return *min_element(v.begin(), v.end());}
template<typename T> inline T MAX(const vector<T> &v){return *max_element(v.begin(), v.end());}

template<typename T,typename S> ostream&operator<<(ostream&os,const pair<T,S>&p){os<<"("<<p.first<<", "<<p.second<<")";return os;}
template<typename T,typename S> ostream&operator<<(ostream&os,const map<T,S>&ma){for(auto [a,b]:ma){os<<"("<<a<<", "<<b<<")"<<" ";}return os;}
template<typename T> ostream &operator<<(ostream&os,const set<T>&s){os<<"{";for(auto c:s)os<<c<<" ";os<<"}";return os;}
template<typename T> ostream &operator<<(ostream&os,const multiset<T>&s){os<<"{";for(auto c:s)os<<c<<" ";os<<"}";return os;}
template<typename T> ostream &operator<<(ostream&os,const vector<T>&v){os<<"[";for(int i=0;i<v.size();i++){os<<v[i]<<(i==v.size()-1?"":" ");}os<<"]";return os;}

void dump_func() {cerr << endl;}
template<class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail){
    cerr << head;
    if(sizeof...(Tail) == 0) cerr << " ";
    else cerr << ", ";
    dump_func(std::move(tail)...);
}



//#define ONLINE_JUDGE
#ifdef ONLINE_JUDGE
#define dump(...) true
#else
#define dump(...) cerr << __LINE__ << " : (" << #__VA_ARGS__ << ") = "; \
dump_func(__VA_ARGS__)
#endif




void solve(){
    ll y, m, d; cin >> y >> m >> d;
    ll cnt = 0;
    while(y != 1000 or m != 1 or d != 1){
        cnt++;
        d++;
        if(y % 3 != 0 and m % 2 == 0){
            if(d == 20) {
                m++;
                d = 1;
            }
        } else if(d == 21){
            m++;
            d = 1;
        }
        if(m == 11){
            m = 1;
            d = 1;
            y++;
        }
    }
    cout << cnt << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);

    int cases; cin >> cases;
    while(cases--){
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3452
final_rank: 11

code_snippet: //GIVE ME AC!!!!!!!!!!!!!!!!!
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using vl=vector<ll>;
using vi=vector<int>;
using vs=vector<string>;
using vc=vector<char>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using vvc=vector<vc>;
using vd=vector<double>;
using vp=vector<P>;
using vb=vector<bool>;
#define overload4(_1,_2,_3,_4,name,...) name
#define overload3(_1,_2,_3,name,...) name
#define rep1(a) for(__typeof(a) i=0;i<a;i++)
#define rep2(i,a) for(__typeof(a) i=0;i<a;i++)
#define rep3(i,a,b) for(__typeof(a) i=a;i<b;i++)
#define rep4(i,a,b,c) for(__typeof(a) i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(a) for(__typeof(a) i=(a)-1;i>=0;i--)
#define rrep2(i,a) for(__typeof(a) i=(a)-1;i>=0;i--)
#define rrep3(i,a,b) for(__typeof(a) i=(b)-1;i>=(a);i--)
#define rrep(...) overload3(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all1(i) begin(i),end(i)
#define all2(i,a) begin(i),begin(i)+a
#define all3(i,a,b) begin(i)+a,begin(i)+b
#define all(...) overload3(__VA_ARGS__,all3,all2,all1)(__VA_ARGS__)
#define rall(n) (n).rbegin(),(n).rend()
#define pb push_back
#define eb emplace_back
#define MtSaka ios::sync_with_stdio(0);cin.tie(0);cout<<fixed<<setprecision(12)
#define max_(a) *max_element(all(a))
#define min_(a) *min_element(all(a))
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const ll inf=2e18;
const ll MOD=1000000007;
const ll mod=998244353;
const double pi=acos(-1);
template<typename T1,typename T2 >
ostream &operator<<(ostream&os,const pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>
istream &operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T>
ostream &operator<<(ostream&os,const vector<T>&v){for(int i=0;i<(int)v.size();i++){os<<v[i]<<(i+1!=v.size()?" ":"");}return os;}
template<typename T>
istream &operator>>(istream&is,vector<T>&v){for(T &in:v){is>>in;}return is;}
void scan(){}
template<class Head,class... Tail>
void scan(Head&head,Tail&... tail){cin>>head;scan(tail...);}
template<class T>
void print(const T &t){cout<<t<<'\n';}
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail){cout<<head<<' ';print(tail...);}
template<class... T>
void fin(const T &... a){print(a...);exit(0);}
template<typename T>
T sum_(vector<T>a){return accumulate(all(a),T(0));}
template<typename T1,typename T2>
inline bool chmax(T1&a,T2 b){return a<b&&(a=b,true);}
template<typename T1,typename T2>
inline bool chmin(T1&a,T2 b){return a>b&&(a=b,true);}
int main(){
  ll cnt=0;
  map<tuple<ll,ll,ll>,ll>mp;
  rep(i,1,1000){
    rep(j,1,11){
      for(ll k=1;k<=((i%3==0||j%2==1)?20:19);k++){
        mp[tuple{i,j,k}]=cnt++;
      }
    }
  }
  LL(n);
  rep(n){
    LL(y,m,d);
    print(cnt-mp[tuple{y,m,d}]);
  }
}
accuracy: 1
time_ms: 30
memory_kb: 18700
final_rank: 18

code_snippet: /* C++ */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef pair<ll, ll> pint;
const ll MOD = 1000000007;
const ll INF = 922337203685477580;
#define rep(i, n) for(ll i = (ll)0; i < (ll)(n); i++)
#define Rep(i, s, t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265358979323846
#define ifYN(x) cout << (x ? "Yes" : "No") << "\n"
ll dx[4] = {-1, 1, 0, 0};
ll dy[4] = {0, 0, -1, 1};

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll Len(ll n) {
  if (n == 0) return 1;
  ll s = 0;
  while (n != 0) s++, n /= 10;
  return s;
}

ll Sint(ll n) {
  ll ans = 0;
  while (n != 0) ans += n % 10, n /= 10;
  return ans;
}

ll Svec(vector<ll> v){
  ll n = 0;
  rep(i, (ll)v.size()) n += v[i];
  return n;
}

ll GCD(ll a, ll b) {
  return b ? GCD(b, a % b) : a;
}

ll LCM(ll a, ll b){
  return a / GCD(a, b) * b;
}

ll POW(ll a, ll n, ll mod = INF) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

void dis(vector<ll> V) {
  rep(i, V.size()) cout << (i ? " " : "") << V[i];
  cout << endl;
}

void dis2(vector<vector<ll> > v) {
  rep (i, v.size()) {
    rep (j, v[0].size()) cout << v[i][j] << ' ';
    cout << endl;
  }
}

bool cmp(pint a, pint b) { return a.second < b.second; }

//Range Add Query 区間加算、一点取得

struct RAQ {
  private:
    ll N; //2の冪乗
    vector<ll> node;

  public:
    RAQ(vector<ll> V) {
      N = 1;
      while (N < V.size()) N *= 2;
      node.resize(2 * N - 1, 0);
      rep (i, V.size()) node[i + N - 1] = V[i];
    }

    void add(ll a, ll b, ll val, ll k = 0, ll l = 0, ll r = -1) { //[a, b) [l, r)
      if (r < 0) r = N;
      if (r <= a || b <= l) return;
      if (a <= l && r <= b) {
        node[k] += val;
        return;
      }
      add(a, b, val, 2 * k + 1, l, (l + r) / 2);
      add(a, b, val, 2 * k + 2, (l + r) / 2, r);
      return;
    }

    ll get(ll ind) {
      ind += N - 1;
      ll ret = node[ind];
      while (ind > 0) {
        ind = (ind - 1) / 2;
        ret += node[ind];
      }
      return ret;
    }
    void dis() {
      ll ans = 1;
      ll id = 0;
      while (1) {
        rep (i, ans) cout << (i ? " " : "") << node[id], id++;
        cout << endl;
        if (ans == N) return;
        ans *= 2;
      }
    }
};

struct T {
  ll y;
  ll m;
  ll d;
};

ll f(ll y, ll m, ll d) {
  ll sum = 0;
  while(1) {
    if (y == 1000 && m == 1 && d == 1) break;
    sum++;
    if(y % 3 == 0) {
      if(d == 20) {
        d = 1;
        if(m == 10) {
          m = 1;
          y++;
        } else {
          m++;
        }
      } else {
        d++;
      }
    } else {
      if(m%2 == 1) {
        if(d == 20) {
          d = 1;
          if(m == 10) {
            m = 1;
            y++;
          } else {
            m++;
          }
        } else {
          d++;
        }
      } else {
        if(d == 19) {
          d = 1;
          if(m == 10) {
            m = 1;
            y++;
          } else {
            m++;
          }
        } else {
          d++;
        }
      }
    }
  }
  return sum;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll N; cin >> N;
  rep(i, N) {
    ll y, m, d; cin >> y >> m >> d;
    cout << f(y, m, d) << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3380
final_rank: 9

code_snippet: #include<iostream>

using namespace std;


signed main(){
	
	int n;
	
	cin>>n;
	
	for(int _ = 0; _ < n; _++){
		int Y, M, D;
		int con = 0;
		
		cin>>Y>>M>>D;
		
		while(Y < 1000){
			con++;
			
			
			if(Y%3 == 0) {
				if(D == 20) M++, D = 1;
				else D++;
			} else {
				if(M%2) {
					if(D == 20) M++, D = 1;
					else D++;
				} else {
					if(D == 19) M++, D = 1;
					else D++;
				}
			}
			
			if(M == 11) Y++, M = 1;
		}
		
		cout<<con<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3348
final_rank: 5

code_snippet: #include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i=n;i--;)
#define rrep2(i,n) for(ll i=n;i--;)
#define rrep3(i,a,b) for(ll i=b;i-->(a);)
#define rrep4(i,a,b,c) for(ll i=(a)+((b)-(a)-1)/(c)*(c);i>=(a);i-=c)
#define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(i) begin(i), end(i)
#define rall(i) (i).rbegin(), (i).rend()
#define Sort(a) sort(all(a))
#define Rev(a) reverse(all(a))
#define elif else if
template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> ll sum(const T& a){ return accumulate(all(a), 0LL); }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }
vector<ll> iota(ll n, ll begin = 0){ vector<ll> a(n); iota(a.begin(), a.end(), begin); return a; }
const int INF =0x3fffffff;
const ll INFll =0x1fffffffffffffff;// 4times ok
const int MOD= int(1e9)+7;
const int MODD=998244353;
using P= pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using VVl=vector<vector<ll>>;
using VVd=vector<vector<ld>>;
using Vd=vector<ld>;
using tuplis =array<ll, 3>;
using quatro=array<ll,4>;
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
const ll four[] = {0, 1, 0, -1, 0};
const ll eight[] = {0, 1, 1, 0, -1, -1, 1, -1, 0};
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll isqr(ll x){ll r=sqrt(x)-1;while((r+1)*(r+1)<=x)r++;return r;}
vector<ll> divisor(ll x){vector<ll> ans; for(ll i = 1; i * i <= x; i++) if(x % i == 0) ans.push_back(i); rrep(ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]); return ans; }
int scan(){ return getchar(); }
void scan(int& a){ scanf("%d", &a); }
void scan(unsigned& a){ scanf("%u", &a); }
void scan(long& a){ scanf("%ld", &a); }
void scan(long long& a){ scanf("%lld", &a); }
void scan(unsigned long long& a){ scanf("%llu", &a); }
void scan(char& a){ do{ a = getchar(); }while(a == ' ' || a == '\n'); }
void scan(float& a){ scanf("%f", &a); }
void scan(double& a){ scanf("%lf", &a); }
void scan(long double& a){ scanf("%Lf", &a); }
void scan(vector<bool>& a){ for(unsigned i = 0; i < a.size(); i++){ int b; scan(b); a[i] = b; } }
void scan(char a[]){ scanf("%s", a); }
void scan(string& a){ cin >> a; }
template<class T> void scan(vector<T>&);
template<class T, size_t size> void scan(array<T, size>&);
template<class T, class L> void scan(pair<T, L>&);
template<class T, size_t size> void scan(T(&)[size]);
template<class T> void scan(vector<T>& a){ for(auto&& i : a) scan(i); }
template<class T> void scan(deque<T>& a){ for(auto&& i : a) scan(i); }
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i); }
template<class T, class L> void scan(pair<T, L>& p){ scan(p.first); scan(p.second); }
template<class T, size_t size> void scan(T (&a)[size]){ for(auto&& i : a) scan(i); }
template<class T> void scan(T& a){ cin >> a; }
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){ scan(head); in(tail...); }
void print(){ putchar(' '); }
void print(bool a){ printf("%d", a); }
void print(int a){ printf("%d", a); }
void print(unsigned a){ printf("%u", a); }
void print(long a){ printf("%ld", a); }
void print(long long a){ printf("%lld", a); }
void print(unsigned long long a){ printf("%llu", a); }
void print(char a){ printf("%c", a); }
void print(char a[]){ printf("%s", a); }
void print(const char a[]){ printf("%s", a); }
void print(float a){ printf("%.15f", a); }
void print(double a){ printf("%.15f", a); }
void print(long double a){ printf("%.15Lf", a); }
void print(const string& a){ for(auto&& i : a) print(i); }
template<class T> void print(const complex<T>& a){ if(a.real() >= 0) print('+'); print(a.real()); if(a.imag() >= 0) print('+'); print(a.imag()); print('i'); }
template<class T> void print(const vector<T>&);
template<class T, size_t size> void print(const array<T, size>&);
template<class T, class L> void print(const pair<T, L>& p);
template<class T, size_t size> void print(const T (&)[size]);
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T> void print(const deque<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T, size_t size> void print(const array<T, size>& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } }
template<class T, class L> void print(const pair<T, L>& p){ print(p.first); putchar(' '); print(p.second); }
template<class T, size_t size> void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ putchar(' '); print(*i); } }
template<class T> void print(const T& a){ cout << a; }
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
#define INT(...) int __VA_ARGS__; in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__; in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__; in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__; in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size); in(name)
#define VV(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); in(name)

int main(){
    LL(n);
    while(n--){
        LL(y,m,d);
        ll ret=0;
        while(y!=1000){
            ret++;
            d++;
            ll mxd=20;
            if(y%3!=0 and m%2==0)mxd--;
            if(d>mxd){
                d=1;
                m++;
            }
            if(m>10){
                m=1;
                y++;
            }
        }
        out(ret);
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3276
final_rank: 4

code_snippet: #line 1 "/Users/nok0/Documents/Programming/nok0/cfmulti.hpp"
#include <bits/stdc++.h>
using namespace std;

#pragma region Macros
// rep macro
#define foa(v, a) for(auto &v : a)
#define REPname(a, b, c, d, e, ...) e
#define REP(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int i = 0; i < (x); ++i)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define REPSname(a, b, c, ...) c
#define REPS(...) REPSname(__VA_ARGS__, REPS1, REPS0)(__VA_ARGS__)
#define REPS0(x) for(int i = 1; i <= (x); ++i)
#define REPS1(i, x) for(int i = 1; i <= (x); ++i)
#define RREPname(a, b, c, d, e, ...) e
#define RREP(...) RREPname(__VA_ARGS__, RREP3, RREP2, RREP1, RREP0)(__VA_ARGS__)
#define RREP0(x) for(int i = (x)-1; i >= 0; --i)
#define RREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define RREP2(i, r, l) for(int i = (r)-1; i >= (l); --i)
#define RREP3(i, r, l, c) for(int i = (r)-1; i >= (l); i -= (c))
#define RREPSname(a, b, c, ...) c
#define RREPS(...) RREPSname(__VA_ARGS__, RREPS1, RREPS0)(__VA_ARGS__)
#define RREPS0(x) for(int i = (x); i >= 1; --i)
#define RREPS1(i, x) for(int i = (x); i >= 1; --i)

// name macro
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
template <class T = int>
using V = std::vector<T>;
template <class T = int>
using VV = std::vector<std::vector<T>>;
template <class T>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
using ll = long long;
using ld = long double;
using int128 = __int128_t;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

// input macro
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
	for(T &i : v) is >> i;
	return is;
}
std::istream &operator>>(std::istream &is, __int128_t &a) {
	std::string s;
	is >> s;
	__int128_t ret = 0;
	for(int i = 0; i < s.length(); i++)
		if('0' <= s[i] and s[i] <= '9')
			ret = 10 * ret + s[i] - '0';
	a = ret * (s[0] == '-' ? -1 : 1);
	return is;
}
namespace scanner {
void scan(int &a) { std::cin >> a; }
void scan(long long &a) { std::cin >> a; }
void scan(std::string &a) { std::cin >> a; }
void scan(char &a) { std::cin >> a; }
void scan(char a[]) { std::scanf("%s", a); }
void scan(double &a) { std::cin >> a; }
void scan(long double &a) { std::cin >> a; }
template <class T, class U>
void scan(std::pair<T, U> &p) { std::cin >> p; }
template <class T>
void scan(std::vector<T> &a) { std::cin >> a; }
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#define VEC(type, name, size)     \
	std::vector<type> name(size); \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                                    \
	std::vector<std::vector<type>> name(h, std::vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)             \
	std::string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)

// output-macro
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &a) {
	for(int i = 0; i < int(a.size()); ++i) {
		if(i) os << " ";
		os << a[i];
	}
	return os;
}
std::ostream &operator<<(std::ostream &dest, __int128_t &value) {
	std::ostream::sentry s(dest);
	if(s) {
		__uint128_t tmp = value < 0 ? -value : value;
		char buffer[128];
		char *d = std::end(buffer);
		do {
			--d;
			*d = "0123456789"[tmp % 10];
			tmp /= 10;
		} while(tmp != 0);
		if(value < 0) {
			--d;
			*d = '-';
		}
		int len = std::end(buffer) - d;
		if(dest.rdbuf()->sputn(d, len) != len) {
			dest.setstate(std::ios_base::badbit);
		}
	}
	return dest;
}
template <class T>
void print(const T a) { std::cout << a << '\n'; }
template <class Head, class... Tail>
void print(Head H, Tail... T) {
	std::cout << H << ' ';
	print(T...);
}
template <class T>
void printel(const T a) { std::cout << a << '\n'; }
template <class T>
void printel(const std::vector<T> &a) {
	for(const auto &v : a)
		std::cout << v << '\n';
}
template <class Head, class... Tail>
void printel(Head H, Tail... T) {
	std::cout << H << '\n';
	printel(T...);
}
void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); }
void No() { std::cout << "No\n"; }
void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); }
void NO() { std::cout << "NO\n"; }
void err(const bool b = true) {
	if(b) {
		std::cout << "-1\n", exit(0);
	}
}

//debug macro
namespace debugger {
template <class T>
void view(const std::vector<T> &a) {
	std::cerr << "{ ";
	for(const auto &v : a) {
		std::cerr << v << ", ";
	}
	std::cerr << "\b\b }";
}
template <class T>
void view(const std::vector<std::vector<T>> &a) {
	std::cerr << "{\n";
	for(const auto &v : a) {
		std::cerr << "\t";
		view(v);
		std::cerr << "\n";
	}
	std::cerr << "}";
}
template <class T, class U>
void view(const std::vector<std::pair<T, U>> &a) {
	std::cerr << "{\n";
	for(const auto &p : a) std::cerr << "\t(" << p.first << ", " << p.second << ")\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &p : m) std::cerr << "\t[" << p.first << "] : " << p.second << "\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::pair<T, U> &p) { std::cerr << "(" << p.first << ", " << p.second << ")"; }
template <class T>
void view(const std::set<T> &s) {
	std::cerr << "{ ";
	for(auto &v : s) {
		view(v);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <class T>
void view(const T &e) { std::cerr << e; }
}  // namespace debugger
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	debugger::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(false)
#else
#define debug(...) (void(0))
#endif

// vector macro
template <class T>
int lb(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x))); }
template <class T>
int ub(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x))); }
template <class T>
void UNIQUE(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<T> press(std::vector<T> &a) {
	auto res = a;
	UNIQUE(res);
	for(auto &v : a)
		v = lb(res, v);
	return res;
}
#define SORTname(a, b, c, ...) c
#define SORT(...) SORTname(__VA_ARGS__, SORT1, SORT0, ...)(__VA_ARGS__)
#define SORT0(a) std::sort((a).begin(), (a).end())
#define SORT1(a, c) std::sort((a).begin(), (a).end(), [](const auto x, const auto y) { return x c y; })
template <class T>
void ADD(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v += x;
}
template <class T>
void SUB(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v -= x;
}
template <class T>
void MUL(std::vector<T> &a, const T x) {
	for(auto &v : a) v *= x;
}
template <class T>
void DIV(std::vector<T> &a, const T x) {
	for(auto &v : a) v /= x;
}
std::vector<std::pair<char, int>> rle(const string &s) {
	int n = s.size();
	std::vector<std::pair<char, int>> ret;
	for(int l = 0; l < n;) {
		int r = l + 1;
		for(; r < n and s[l] == s[r]; r++) {}
		ret.emplace_back(s[l], r - l);
		l = r;
	}
	return ret;
}
template <class T>
std::vector<std::pair<T, int>> rle(const std::vector<T> &v) {
	int n = v.size();
	std::vector<std::pair<T, int>> ret;
	for(int l = 0; l < n;) {
		int r = l + 1;
		for(; r < n and v[l] == v[r]; r++) {}
		ret.emplace_back(v[l], r - l);
		l = r;
	}
	return ret;
}

// math macro
template <class T, class U>
inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }
template <class T, class U>
inline bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; }
template <class T>
T divup(T x, T y) { return (x + y - 1) / y; }
template <class T>
T POW(T a, long long n) {
	T ret = 1;
	while(n) {
		if(n & 1) ret *= a;
		a *= a;
		n >>= 1;
	}
	return ret;
}
// modpow
long long POW(long long a, long long n, const int mod) {
	long long ret = 1;
	a = (a % mod + mod) % mod;
	while(n) {
		if(n & 1) (ret *= a) %= mod;
		(a *= a) %= mod;
		n >>= 1;
	}
	return ret;
}

// others
struct fast_io {
	fast_io() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} fast_io_;
const int inf = 1e9;
const ll INF = 1e18;
#pragma endregion

void main_();

int main() {
	int t;
	cin >> t;
	while(t--) main_();
	return 0;
}
#line 2 "a.cpp"

void main_() {
	INT(y, m, d);
	ll res = 0;
	while(y != 1000) {
		res++;
		bool big = 0;
		if(m & 1) big = 1;
		if(y % 3 == 0) big = 1;
		int MAX = (big ? 20 : 19);
		if(d < MAX) {
			d++;
			continue;
		} else {
			m++;
			d = 1;
			if(m == 11) {
				m = 1;
				y++;
			}
		}
	}
	print(res);
}
accuracy: 1
time_ms: 10
memory_kb: 3356
final_rank: 8