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