#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5, L = 14, OO = 0x3f3f3f3f;
const long long M = 1000000007;
const double ESP = 1e-8;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t, a, b;
  cin >> t;
  while (t--) {
    cin >> a >> b;
    int mul = (a + b - 1) / b;
    b *= mul;
    cout << b - a << "\n";
  }
}
