#include <bits/stdc++.h>
int main() {
  int t, h, m, tot;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &h, &m);
    tot = 60 - m;
    h++;
    tot += (24 - h) * 60;
    printf("%d\n", tot);
  }
  return 0;
}
