#define TEST
#undef TEST //実装時にはこれをコメントアウトしないようにすること

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using sc = Scanner;

class Program
{

    static void Main(string[] args)
    {
        int n = sc.NextInt();
        int aniversaryFromOrigin = 590*333;// YMD が1,1,1のときからミレニアム記念日までかかる日にち
        var q = new AnswerCollecter<int>();
        int[] year = {195,195,200};
        int[] month = {20,19};
        for (int i = 0; i < n; i++)
        {
            int answer = aniversaryFromOrigin;
            int[] YMD = sc.NextIntArray();
            int progressYear = YMD[0] - 1;
            int progressMonth = YMD[1] - 1;
            int progressDay = YMD[2] - 1;
            for (int j = 0; j < progressYear; j++)
            {
                answer -= year[j % 3];
            }
            for (int j = 0; j < progressMonth; j++)
            {
                answer -= progressYear % 3 == 2? 20 : month[j % 2] ;
            }
            answer -= progressDay;
            q.Enqueue(answer);
        }
        q.Answer();
#if TEST

    Console.ReadLine();
#endif
    }


}

public class AnswerCollecter<T>
{
    private Queue<T> q;



    public AnswerCollecter()
    {
        q = new Queue<T>();
    }

    public void Enqueue( T item)
    {
        q.Enqueue(item);
    }

    public void Answer()
    {
        while (q.Count != 0)
            Console.WriteLine(q.Dequeue());
    }
    public int Count()
    {
        return q.Count;
    }
}
   
public static class Scanner
{
    public static string NextString()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return tmp;
    }

    public static string[] NextStrArray()
    {
        return Console.ReadLine().Split(' ');
    }

    public static long[] NextLongArray()
    {
        string[] s = NextStrArray();
        long[] a = new long[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = long.Parse(s[i]);
        }
        return a;
    }
    public static int[] NextIntArray()
    {

        string[] s = NextStrArray();
        int[] a = new int[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        return a;
    }
    public static int NextInt()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
        
            tmp += readData;
        }
        return int.Parse(tmp);
    }
    public static double NextDouble()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return double.Parse(tmp);
    }
    public static long NextLong()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return long.Parse(tmp);
    }
    public static double[] NextDoubleArray()
    {

        string[] s = NextStrArray();
        double[] a = new double[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = double.Parse(s[i]);
        }
        return a;
    }
}

Measured memory_bytes: 7992