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