#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int h, m, time;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &h, &m);
    h = 23 - h;
    m = 60 - m;
    time = (h * 60) + m;
    printf("%d\n", time);
  }
}
