#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool uax(T &x, T y) {
  return (y > x) ? x = y, true : false;
}
template <typename T>
inline bool uin(T &x, T y) {
  return (y < x) ? x = y, true : false;
}
template <typename T>
void kek(T ans) {
  cout << ans << endl;
  exit(0);
}
const int MOD = (int)1e9 + 7;
const long long INF = (long long)1e18 + 42;
void solve_case() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> a(n);
  int cx = 0, cy = 0;
  for (int i = 0; i < k; ++i) {
    int x = 0, y = 0;
    for (int j = i; j < n; j += k) {
      x |= s[j] == '0';
      y |= s[j] == '1';
    }
    if (x && y) {
      cout << "NO\n";
      return;
    }
    if (x)
      cx++;
    else if (y)
      cy++;
  }
  cout << (cx <= k / 2 && cy <= k / 2 ? "YES\n" : "NO\n");
}
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int tt;
  cin >> tt;
  while (tt--) {
    solve_case();
  }
}
