#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int t1, t2;
    cin >> t1 >> t2;
    int ans = 0;
    ans += 60 - t2;
    ans += (24 - (t1 + 1)) * 60;
    cout << ans << endl;
  }
  return 0;
}
