#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  {
    long long int a;
    cin >> a;
    while (a--) {
      long long int x, y, ans = 0, temp = 0, temp1 = 0;
      cin >> x >> y;
      if (x % y == 0)
        cout << "0"
             << "\n";
      else {
        temp = x / y;
        temp1 = (temp * y) + y;
        ans = temp1 - x;
        cout << ans << "\n";
      }
    }
  }
  return 0;
}
