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