#include <bits/stdc++.h>
using namespace std;
int main() {
  int ent;
  long long int a, b;
  cin >> ent;
  while (ent--) {
    int div = 0, pls = 0;
    cin >> a >> b;
    if (a % b == 0) {
      cout << 0 << endl;
      continue;
    }
    div = a / b;
    pls = (div + 1) * b;
    cout << pls - a << endl;
  }
}
