#include <bits/stdc++.h>
using namespace std;
int T, H, M;
int main() {
  cin >> T;
  int E = 24 * 60;
  while (T--) {
    cin >> H >> M;
    M += H * 60;
    cout << E - M << '\n';
  }
  return 0;
}
