#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
void solve() {
  int a, b;
  cin >> a >> b;
  int t = a % b;
  if (t == 0)
    cout << 0 << endl;
  else
    cout << b - t << endl;
}
