#include <bits/stdc++.h>
using namespace std;
auto clk = clock();
mt19937_64 rang(
    chrono::high_resolution_clock::now().time_since_epoch().count());
void test_case() {
  long long int h, m;
  cin >> h >> m;
  h = 24 - h - 1;
  m = 60 - m;
  cout << h * 60 + m << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  cout << fixed << setprecision(10);
  long long int t = 1;
  cin >> t;
  while (t--) {
    test_case();
  }
  return 0;
}
