#include using namespace std; //#pragma GCC optimize("Ofast") #define rep(i,n) for(ll i=0;i=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue,greater> #define all(x) (x).begin(),(x).end() #define CST(x) cout<> #define rev(x) reverse(x); using ll=long long; using vl=vector; using vvl=vector>; using pl=pair; using vpl=vector; using vvpl=vector; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[9]={1,0,-1,0,1,1,-1,-1,0}; const ll dx[9]={0,1,0,-1,1,-1,1,-1,0}; template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } void solve(){ ll n,k,x;cin >> n >> k >> x; vl v(n);rep(i,n)cin >> v[i]; bool ok=true; rep(i,k){ vl z; ll j=i; bool last=false; while(j<=n){ if(j!=0&&j!=n)z.emplace_back(v[j]-v[j-1]); else z.emplace_back(INF); if(j==n)last=true; j+=k; } //cout << last << endl; //for(auto p:z)cout << p <<" ";cout << endl; if(i!=0){ rep(k,z.size()-1){ if(z[k]>0)ok=false; if(z[k]%x)ok=false; z[k+1]+=z[k]; } if((!last)&&z.back()!=0)ok=false; } else{ if(last){ repl(k,1,z.size()-1){ if(z[k]%x)ok=false; } } else{ rev(all(z)); rep(k,z.size()-1){ if(z[k]<0)ok=false; if(z[k]%x)ok=false; z[k+1]+=z[k]; } } } } if(ok)cout << "Yes" << endl; else cout << "No" << endl; } int main(){ ll t;cin >> t; while(t--){ solve(); } }