#include<bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define endl '\n'
#define ll long long int
#define vi vector<int>
#define mx(a,b,c,d) max(a, max(b, max(c,d)))
#define MP make_pair
#define pb push_back
#define ppb pop_back
const int md = 1e9 + 7;
const ll INF=1e9+15;
const ll NAX= 2e5+5; // change it acc tothe contraints
void solve()
{
ll n;
cin>>n;
ll num;
cin>>num;
ll new_num=num;
vector<ll> arr;
while(num!=0){
ll temp=num%10;
arr.pb(temp);
num/=10;
break;
}
// debug(arr);
vector<string>numbers;
string str_9=" ";
for(int i=0; i<n; i++){
numbers.pb("9");
str_9+=numbers[i];
//debug(arr,str_9, numbers);
}
ll num_9=stoll(str_9);
if(arr[0]!=9){
cout<<num_9-new_num<<endl;;
return;
}
else{
numbers.clear();
string str_1=" ";
ll num_1;
for(int i=0; i<n-1; i++){
numbers.pb("1");
str_1+=numbers[i];
}
str_1+="2";
num_1=stoll(str_1);
cout<<num_1<<endl;
//debug(str_1, num_1, numbers);
return;
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int tc=1;
cin>>tc;
for (int i=0; i<tc; i++){
solve();
//cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdm9pZCBfX3ByaW50KGludCB4KSB7Y2VyciA8PCB4O30Kdm9pZCBfX3ByaW50KGxvbmcgeCkge2NlcnIgPDwgeDt9CnZvaWQgX19wcmludChsb25nIGxvbmcgeCkge2NlcnIgPDwgeDt9CnZvaWQgX19wcmludCh1bnNpZ25lZCB4KSB7Y2VyciA8PCB4O30Kdm9pZCBfX3ByaW50KHVuc2lnbmVkIGxvbmcgeCkge2NlcnIgPDwgeDt9CnZvaWQgX19wcmludCh1bnNpZ25lZCBsb25nIGxvbmcgeCkge2NlcnIgPDwgeDt9CnZvaWQgX19wcmludChmbG9hdCB4KSB7Y2VyciA8PCB4O30Kdm9pZCBfX3ByaW50KGRvdWJsZSB4KSB7Y2VyciA8PCB4O30Kdm9pZCBfX3ByaW50KGxvbmcgZG91YmxlIHgpIHtjZXJyIDw8IHg7fQp2b2lkIF9fcHJpbnQoY2hhciB4KSB7Y2VyciA8PCAnXCcnIDw8IHggPDwgJ1wnJzt9CnZvaWQgX19wcmludChjb25zdCBjaGFyICp4KSB7Y2VyciA8PCAnXCInIDw8IHggPDwgJ1wiJzt9CnZvaWQgX19wcmludChjb25zdCBzdHJpbmcgJngpIHtjZXJyIDw8ICdcIicgPDwgeCA8PCAnXCInO30Kdm9pZCBfX3ByaW50KGJvb2wgeCkge2NlcnIgPDwgKHggPyAidHJ1ZSIgOiAiZmFsc2UiKTt9Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBULCB0eXBlbmFtZSBWPgp2b2lkIF9fcHJpbnQoY29uc3QgcGFpcjxULCBWPiAmeCkge2NlcnIgPDwgJ3snOyBfX3ByaW50KHguZm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07CiAgICB2ZWN0b3I8bGw+IGFycjsKCiAgICB3aGlsZShudW0hPTApewogICAgICAgIGxsIHRlbXA9bnVtJTEwOwogICAgICAgIGFyci5wYih0ZW1wKTsKICAgICAgICBudW0vPTEwOwogICAgICAgIGJyZWFrOwogICAgfQogLy8gICBkZWJ1ZyhhcnIpOwogICAgdmVjdG9yPHN0cmluZz5udW1iZXJzOwogICAgc3RyaW5nIHN0cl85PSIgIjsKICAgIGZvcihpbnQgaT0wOyBpPG47IGkrKyl7CiAgICAgICAgbnVtYmVycy5wYigiOSIpOwogICAgICAgIHN0cl85Kz1udW1iZXJzW2ldOwogICAgICAgIC8vZGVidWcoYXJyLHN0cl85LCBudW1iZXJzKTsKICAgIH0KICAgIGxsIG51bV85PXN0b2xsKHN0cl85KTsKICAgIGlmKGFyclswXSE9OSl7CiAgICAgICAgY291dDw8bnVtXzktbmV3X251bTw8ZW5kbDs7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgZWxzZXsKICAgICAgICBudW1iZXJzLmNsZWFyKCk7CiAgICAgICAgc3RyaW5nIHN0cl8xPSIgIjsKICAgICAgICBsbCBudW1fMTsKICAgICAgICBmb3IoaW50IGk9MDsgaTxuLTE7IGkrKyl7CiAgICAgICAgICAgIG51bWJlcnMucGIoIjEiKTsKICAgICAgICAgICAgc3RyXzErPW51bWJlcnNbaV07CiAgICAgICAgfQogICAgICAgIHN0cl8xKz0iMiI7CiAgICAgICAgbnVtXzE9c3RvbGwoc3RyXzEpOwogICAgICAgIGNvdXQ8PG51bV8xPDxlbmRsOwogICAgICAgIC8vZGVidWcoc3RyXzEsIG51bV8xLCBudW1iZXJzKTsKICAgICAgICByZXR1cm47CiAgICAKICAgIH0KCn0KaW50IG1haW4oKSB7CgkJCiAgICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCksIGNpbi50aWUoMCksIGNvdXQudGllKDApOwoKaW50IHRjPTE7CiAgICBjaW4+PnRjOwogICAgZm9yIChpbnQgaT0wOyBpPHRjOyBpKyspewoJCXNvbHZlKCk7CgkJLy9jZXJyIDw8ICJ0aW1lIHRha2VuIDogIiA8PCAoZmxvYXQpY2xvY2soKSAvIENMT0NLU19QRVJfU0VDIDw8ICIgc2VjcyIgPDwgZW5kbDsKCgkJfQoJCQoKCn0KCgog