#include <bits/stdc++.h>
using namespace std;
const int mxN = 5e5 + 5;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    if (a % b == 0) {
      cout << 0 << endl;
      continue;
    }
    if (a >= b) {
      cout << b - a % b << endl;
    } else
      cout << b - a << endl;
  }
}
