#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int h, m;
  cin >> h >> m;
  long long int ans = 60 * (23 - h) + 60 - m;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
