#include<bits/stdc++.h> using namespace std; int T,h,m; signed main() { cin>>T; while(T--) { cin>>h>>m; cout<<(23-h)*60+60-m<<endl; } return 0; }