#include <iostream>
using namespace std;
int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
    int n;
    while (cin >> n) {
        int year, month, day;
        for (int i = 0; i < n; ++i) {
            cin >> year >> month >> day;
            if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
                days[2] = 29;
            } else {
                days[2] = 28;
            }
            int sum = 0;
            for (int i = 1; i < month; ++i) {
                sum += days[i];
            }
            sum += day;
            cout << sum << endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

优雅又简洁