#include <iostream> using namespace std; int x,y,T; int main() { cin>>T; while(T--) cin>>x>>y,cout<<24*60-x*60-y<<endl; return 0; }