#!/usr/bin/node
// Generated by CoffeeScript 1.3.3 (minified manually)
(function() {
  var a=[],stdin;
  stdin=process.openStdin();
  stdin.setEncoding('utf8');

  stdin.on('data', function(input) {
    var x = input.split("\n");
    if(x.length > 2 || x[1] !== '')a = x;
    else a.push(x[0]);
  });

  stdin.on('end', function(z) {
    var b, i, j, m, n, r, y;
    n = parseInt(a.shift());
    for(i=0;i<n;i++){
      b = a[i].split(" ");
      for(j=0;j<b.length;j++)b[j]=parseInt(b[j]);
      y = b[0] - 1;
      m = b[1] - 1;
      r = 0;
      if (y % 3 !== 2) {
        r = Math.floor(m / 2);
      }
      console.log(196471 - y * 195 - Math.floor(y / 3) * 5 - m * 20 + r - b[2]);
    }
  });
}).call(this);