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