#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int T;
  cin >> T;
  while (T--) {
    long long int t, n, i, j, x, y, m, l, d, k;
    cin >> n >> m;
    long long int ans = 60 - m;
    n++;
    ans += (24 - n) * 60;
    cout << ans << "\n";
  }
}
