#include using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; #define rep(i,n) for(ll i=0;i T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); } template T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); } template inline bool chmin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; } template ostream &operator<<(ostream &os, const vector &a){ if (a.empty()) return os; os << a.front(); for (auto e : a | views::drop(1)){ os << ' ' << e; } return os; } void dump(auto ...vs){ ((cout << vs << ' '), ...) << endl; } #include using namespace atcoder; using mint = modint998244353; ll solve_all(ll X,ll M,ll e){ ll ans=2e18; ll te=intpow(10,e); for (ll d=e;d<=18-e;d++){ ll r=X*(1+pow_mod(10,d,M)); r=M-r; r%=M; r+=M; r%=M; ll g=gcd(te,M); ll tg=te/g; ll mg=M/g; if (r%g!=0){ continue; } r/=g; ll y=r*inv_mod(tg,mg); y%=mg; if (y=1e18){ cout<<-1<<'\n'; } else{ cout<=1e18){ cout<<-1<<'\n'; } else{ cout<=1e18){ cout<<-1<<'\n'; } else{ cout<>X>>M; string xs=to_string(X); if (xs.size()==1){ solve1(X,M); } else if (xs.size()==2){ solve2(X,M); } else if (xs.size()==3){ solve3(X,M); } return; } int main() { cin.tie(0)->sync_with_stdio(0); ll T=1; cin>>T; while (T--){ solve(); } return 0; }