#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 7, M = 1e5 + 7, mod = 1e9 + 7, inf = 1e18 + 7;
long long ar[N];
long long tc, n, m, a, b, c, d, i, j, sum;
vector<long long> vec;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> tc;
  while (tc--) {
    cin >> a >> b;
    cout << (24 - a - 1) * 60 + 60 - b << endl;
  }
}
