#include #include #define rp(n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=sta;i--) #define fore(i, a) for(auto &&i : a) #define foreP(a, b, v) for(auto &&[a, b] : v) #define foreP3(a, b, c, v) for(auto &&[a, b, c] : v) #define fitr(itr, m) for(auto &&itr=m.begin();itr!=m.end();itr++) #define all(v) (v).begin(),(v).end() #define Sum(a) accumulate(all(a),0LL) #define VC vector #define TP tuple using namespace std; mt19937 engine(time(0)); using ll = long long; using ld = long double; constexpr long long mod = 998244353; // constexpr long long mod = 1000000007; // constexpr long long mod = 100000000000000003; constexpr double PI=3.1415926535897932384626433832795028841971; constexpr long long inf = INT_MAX; constexpr long long infll = LONG_MAX; int dx[8] = {1, 0,-1, 0, 1, 1,-1,-1}; int dy[8] = {0, 1, 0,-1, 1,-1, 1,-1 }; using Si =set; using Sll =set; using Sc =set; using Ss =set; using Mii = map; using Msi = map; using Mci = map; using Mlli = map; using T3 = tuple; using TL3 = tuple; using P = pair; using PL = pair; using V = vector; using VL = vector; using Vc = vector; using Vs = vector; using VV = vector>; using VVL = vector>; using VVV = vector>>; using VP = vector

; using VVP = vector>; templateusing MaxHeap = priority_queue; templateusing MinHeap = priority_queue, greater>; templatevoid chmin(T& a, T b) {a = min(a, b);} templatevoid chmax(T& a, T b) {a = max(a, b);} ll modpow(ll x, ll n, ll m = mod) { if (n < 0) { ll res = modpow(x, -n, m); return modpow(res, m - 2, m); } if (abs(x) >= m)x %= m; if (x < 0)x += m; //if (x == 0)return 0; ll res = 1; while (n) { if (n & 1)res = res * x % m; x = x * x % m; n >>= 1; } return res; } class modint { public: int val; modint() :val(0) {} templatemodint(T x=0): val(x%mod){if(val<0)val+=mod;} modint(const modint &r){val=r.val;} modint& operator=(const modint& other) {val = other.val;return *this;} modint& operator=(const int& other) {val = other;return *this;} modint& operator=(const long long& other) {val = other;return *this;} //算術演算子 modint operator +(){return (*this);} //単項 modint operator -(){return (val%mod+mod)%mod;} //単項 modint operator +(const modint &r){return modint(*this)+=r;} modint operator -(const modint &r){return modint(*this)-=r;} modint operator *(const modint &r){return modint(*this)*=r;} modint operator /(const modint &r){return modint(*this)/=r;} modint operator %(const modint &r){return modint(*this)%=r;} modint operator ^(long long r){modint ans = 1, x = val;while (r > 0) {if (r & 1) ans *= x;x *= x;r >>= 1;}return ans;} modint operator ++(int){val+=1;val%=mod; return *this;} modint operator --(int){(val==0)?val=mod-1:val-=1; return *this;} //代入演算子 modint &operator +=(const modint &r){val+=r.val;if(val>=mod)val-=mod;return *this;} modint &operator -=(const modint &r){if(valval==r.val;} bool operator <(const modint& r){return this->val(const modint& r){return this->val>r.val;} bool operator !=(const modint& r){return this->val!=r.val;} // 他のクラスとの計算 template friend modint operator+(T t, const modint& o) {return modint(t) + o;} template friend modint operator-(T t, const modint& o) {return modint(t) - o;} template friend modint operator*(T t, const modint& o) {return modint(t) * o;} template friend modint operator/(T t, const modint& o) {return modint(t) / o;} }; istream &operator >>(istream &is,modint& x){ long long t; is >> t; x=modint(t); return is;} ostream &operator <<(ostream &os,const modint& x){return os<sputn(d, len) != len) dest.setstate(ios_base::badbit); } return dest; } __int128 parse(string &s) { __int128 ret = 0; for (int i = 0; i < s.size(); i++) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } template T gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b)swap(a, b); while(b){ll r = a % b; a = b; b = r;} return a; } templatevoid debug(T a){cerr << a << endl;} templatevoid debug(T a, S b){cerr << a << " " << b << endl;} templatevoid debug(T a,S b,U c){cerr <<"( "<< a << " " << b << " " << c <<" )" << endl;} templatevoid debug(T a,S b,U c,W d){cerr <<"( "<< a << " " << b << " " << c<< " " << d <<" )" << endl;} templatevoid debug(vector v){for(int i=0;ivoid debug(set m){for(auto itr: m){cerr << itr << " ";}cerr << endl;} templatevoid debug(map m){for(auto itr=m.begin();itr!=m.end();itr++)cerr <<"("<< itr->first << " => " << itr->second<<")" << endl;} templatevoid debug(pair p){cerr <<"( "<< p.first << ", " << p.second <<" )" << endl;} templatevoid debug(tuple t){cerr <<"( "<< get<0>(t) << ", " << get<1>(t) <<" )" << endl;} templatevoid debug(tuple t){cerr <<"( "<< get<0>(t) << ", " << get<1>(t)<< ", " << get<2>(t) <<" )" << endl;} templatevoid debug(tuple t){cerr <<"( "<< get<0>(t) << ", " << get<1>(t)<< ", " << get<2>(t)<< ", " << get<3>(t) <<" )" << endl;} templatevoid out(T a){ cout << a << endl;} templatevoid out(T a,S b){ cout << a <<" " << b << endl;} templatevoid out(T a,S b,U c){ cout << a <<" " << b <<" " << c << endl;} templatevoid out(vector v){ for(int i=0;ivoid out(set m){for(auto itr: m){cout << itr; if((itr+1)==m.endl()) cout << endl;else cout << " ";}} templatevoid out(pair p){cout << p.first << " " << p.second << endl;} templatevoid out(tuple t){cout << get<0>(t) << " " << get<1>(t) << endl;} templatevoid out(tuple t){cout << get<0>(t) << " " << get<1>(t)<< " " << get<2>(t) << endl;} void yes(bool f=1,string yes="Yes",string no="No"){if(f){cout << yes << endl;}else{cout << no << endl;}} struct S { int x; int y; S(int x, int y) : x(x),y(y){} bool operator<(const struct S& other) const { return x < other.x; } void debug(){ cerr <<"debug " << x <<"-" << y << endl; } }; void solve(){ int n,m,b; cin >> n >> m >> b; V a(n); rep(i,n) cin >> a[i]; ll ans = 1; rep(i,n){ ans*=(1+modpow(m,a[i],b))%b; ans %= b; } out(ans); return; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout<> t; while(t--) solve(); return 0; }