import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n;
    scan(n);

    foreach (i ; 0 .. n) {
        int yi, mi, di;
        scan(yi, mi, di);
        writeln(mill(yi, mi, di));
    }
}

int mill(int y, int m, int d) {
    int res;

    if (y % 3 == 0) {
        res += 10 * 20 - ((m - 1) * 20 + d) + 1;
    }
    else {
        res += 5*19 + 5*20 - ((m - 1) / 2 * 39 + ((m-1)&1)*20 + d) + 1;
    }

    foreach (yy ; y + 1 .. 1000) {
        if (yy % 3 == 0) res += 10*20;
        else res += 5*39;
    }

    return res;
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}