#include using namespace std; random_device seed_gen;mt19937 rnd(seed_gen()); using ll = long long;using ull = unsigned long long; using vi = vector;using vvi = vector;using vvvi = vector; using vl = vector;using vvl = vector;using vvvl = vector; templateinline bool chmax(T& a, T b) { return ((a < b) ? (a = b, true) : (false)); } templateinline bool chmin(T& a, T b) { return ((a > b) ? (a = b, true) : (false)); } bool eq(double a, double b) { return abs(a - b) < 0.0000001; } const int di4[4] = { 0,-1,0,1 },dj4[4] = { -1,0,1,0 };//LRUD const int di8[8] = { 0,0,1,1,1,-1,-1,-1 },dj8[8] = { 1,-1,0,-1,1,0,-1,1 }; #define rep(i,n) for(int i=0;i=0;i--) #define Rrep1(i,n) for(int i=n;i>0;i--) #define all(a) a.begin(),a.end() #define yesno(ans) cout<<((ans)?"Yes\n":"No\n") #define YESNO(ans) cout<<((ans)?"YES\n":"NO\n") #define INF ((ll)2e18) #define IINF ((int)(1e9+5e8)) const double PI = 3.1415926535897932384626; #define eb emplace_back #define pb push_back ///*ACL #include using namespace atcoder; using mint=modint; //using mint = modint998244353; //using mint = modint1000000007; using vm = vector;using vvm = vector;using vvvm = vector; //*/ //行列累乗 //行列の要素の型は最初、int型になっています. using matrixElementType=mint;//行列の要素の型 //行列累乗を行う行列は正方行列. using vec=vector; using mat=vector; mat mul(const mat&A,const mat&B){ assert(int(A[0].size())==int(B.size())); mat C(int(A.size()),vec(int(B[0].size()))); for(int i=0;i0){ if(n&1)B=mul(B,A); A=mul(A,A); n>>=1LL; } return B; } int solve() { ll N;cin>>N; int M;cin>>M; modint::set_mod(M); mat A(2,vec(2)); A[0][0]=1,A[0][1]=1; A[1][0]=1,A[1][1]=0; A=pow(A,N-1); mat F(2,vec(1)); F[0][0]=1; F[1][0]=0; F=mul(A,F); cout<>T; while (T--){ solve(); } return 0; }