#include using namespace std; long long mod = 998244353; //入力が必ずmod未満の時に使う. struct mint{ long long v = 0; mint(){} mint(int a){v = a;} mint(long long a){v = a;} mint(unsigned long long a){v = a;} long long val(){return v;} void modu(){v %= mod;} mint repeat2mint(long long a,long long b){ mint ret = 1,p = a; int Log = 60; if(b <= 2e9) Log = 30; for(int i=0; i(mint b){if(v > b.v) return true; else return false;} bool operator>=(mint b){if(v >= b.v) return true; else return false;} bool operator<(mint b){if(v < b.v) return true; else return false;} bool operator<=(mint b){if(v <= b.v) return true; else return false;} mint pow(long long x){return repeat2mint(v,x);} mint inv(){return mint(1)/v;} }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ string s; cin >> s; cin >> mod; reverse(s.begin(),s.end()); int N = s.size(); vector A,B; for(auto c : s) A.push_back((int)(c-'0')); A.push_back(0); B = A; B.at(0)++; for(int i=0; i C; if(A.at(0)%2 == 0){ long long now = 0; for(int i=N-1; i>=0; i--){ long long c = 0; if(now) c = 5; if(A.at(i)%2) now = 1; else now = 0; c += A.at(i)/2; C.push_back(c); } reverse(C.begin(),C.end()); A = C; } else{ long long now = 0; for(int i=N; i>=0; i--){ long long c = 0; if(now) c = 5; if(B.at(i)%2) now = 1; else now = 0; c += B.at(i)/2; C.push_back(c); } reverse(C.begin(),C.end()); B = C; } vector p10(N+1,1); for(int i=1; i<=N; i++) p10.at(i) = p10.at(i-1)*10; mint a = 0,b = 0; for(int i=0; i