#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t, h, m;
  cin >> t;
  while (t--) {
    cin >> h >> m;
    cout << (23 - h) * 60 + 60 - m << '\n';
  }
  return 0;
}
