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