#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)        for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n)    for (int i = (s); i < (int)(n); i++)
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
typedef vector<int> VI;
typedef long long int ll;


int main() {
    int x;
    cin >> x;

    cout << 100-(x%100) << endl;

    return 0;
}
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
ll extgcd(ll a, ll b, ll& x, ll& y) {
    for (ll v = x = 1, u = y = 0; b; ) { ll q = a / b; swap(a -= q * b, b); swap(x -= q * u, u); swap(y -= q * v, v); }
    return a;
}

int main() {
    int T;
    cin >> T;

    rep(t, T) {
        ll N, S, K;
        cin >> N >> S >> K;

        ll G = gcd(N, K);
        if (S % G) {
            write(-1);
            continue;
        }

        ll n = N / G, k = K / G, s = S / G;
        ll x, y;
        ll ret = extgcd(k, -n, x, y);
        assert(abs(ret) == 1);
        if (ret == 1) {
            x *= n - s;
            y *= n - s;
        }
        else {
            x *= s;
            y *= s;
        }
        ll z = min(x / n, y / k);
        x -= n * z;

        write(x);
    }
}
