#include <bits/stdc++.h>
int main() {
  int A, M, rest, time, N, i;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) {
    scanf("%d %d", &A, &M);
    time = (24 - A) * 60;
    rest = time - M;
    printf("%d\n", rest);
  }
  return 0;
}
