#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if (a % b == 0)
      ans = 0;
    else {
      int x = a / b;
      ans = b * (x + 1) - a;
    }
    cout << ans << '\n';
  }
  return 0;
}
