#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define print(v) for(auto &u:v) cout << u << " "
#define printp(v) for(auto e:v) cout<<e.first<<" "<<e.second<<endl;
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define pf push_front
#define printl(li) for(auto &u:li) cout << u;
void solve()
{
int n, k; cin >> n >> k;
cout << k-n << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1; cin >> t;
while(t--)
{
solve();
}
return 0;
}