#include <bits/stdc++.h>
using namespace std;
int main() {
  int m = 1, k = 1, t = 0;
  cin >> t;
  while (t--) {
    int cnt = 0;
    cin >> m >> k;
    if (m > k)
      if (m % k == 0)
        cnt = 0;
      else
        cnt = k * (m / k + 1) - m;
    else
      cnt = k - m;
    cout << cnt << "\n";
  }
  return 0;
}
