#include <bits/stdc++.h>
using namespace std;
int a[10005], b[10005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    cout << 1440 - a[i] * 60 - b[i] << '\n';
  }
  return 0;
}
