#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int a, b;
    cin >> a >> b;
    int num = (b - a % b) % b;
    cout << num << endl;
  }
  return 0;
}
