#include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; bool solve(const int k, const int x, const vector& h) { const int n = h.size(); if (k == n) return ranges::is_sorted(h) && h.front() == h.back(); vector> diff(k); FOR(i, 1, n) { const int index = (i - 1) % k; diff[index].emplace_back(h[i] - h[i - 1]); if (diff[index].back() % x != 0) return false; diff[index].back() /= x; } vector can_op(k, -1); can_op[k - 1] = 1; for (int i = 1; i + k < n; ++i) { if (can_op[(i - 1 + k) % k] == -1) can_op[(i - 1 + k) % k] = 0; } can_op[(n - 1) % k] = (can_op[(n - 1) % k] == -1 ? 2 : (can_op[(n - 1) % k] | 2)); REP(i, k) { if (can_op[i] == -1) { if (ranges::count(diff[i], 0) != diff[i].size()) return false; } else if (can_op[i] == 0) { ll op = 0; for (const ll d : diff[i]) { op += d / x; if (op > 0) return false; } if (op != 0) return false; } else if (can_op[i] == 1) { ll op = 0; for (const ll d : diff[i]) { op += d / x; } if (op < 0) return false; } else if (can_op[i] == 2) { ll op = 0; for (const ll d : diff[i]) { op += d / x; if (op > 0) return false; } } } return true; } int main() { int t; cin >> t; while (t--) { int n, k, x; cin >> n >> k >> x; vector h(n); for (int& h_i : h) cin >> h_i; cout << (solve(k, x, h) ? "Yes\n" : "No\n"); } return 0; }