#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tests;
  cin >> tests;
  while (tests-- > 0) {
    int h, m;
    cin >> h >> m;
    cout << 1440 - 60 * h - m << endl;
  }
  return 0;
}
