#include <iostream>
using namespace std;
int T;
int h,m;
int main()
{
cin >> T;
int H[T],M[T];
for(int i = 0;i < T;i++){
cin >> h >> m;
H[i] = h;
M[i] = m;
}
for(int j = 0;j < T;j++){
int a = (23 - H[j]) * 60 + (60 - M[j]);
cout << a << endl;
}
return 0;
}