#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    long long a, b;
    cin >> a >> b;
    if (b >= a) {
      cout << b - a << "\n";
    } else if (a % b == 0) {
      cout << 0 << "\n";
    } else {
      cout << b - a % b << "\n";
    }
  }
  return 0;
}
