#include <bits/stdc++.h>
const int INF = 1e8;
const long long MOD = 1e9 + 7;
using namespace std;
void solve() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  int op[2];
  bool pos = 1;
  for (int i = 0; i < k; i++) {
    int j = i;
    op[0] = op[1] = 0;
    while (j < n) {
      if (s[j] == '0') op[0] = 1;
      if (s[j] == '1') op[1] = 1;
      j += k;
    }
    char c;
    if (op[0] && op[1])
      pos = 0;
    else if (op[0] == 0 && op[1] == 0)
      continue;
    else if (op[0])
      c = '0';
    else if (op[1])
      c = '1';
    if (!pos) continue;
    j = i;
    while (j < n) {
      s[j] = c;
      j += k;
    }
  }
  int one = 0, zero = 0;
  for (int i = 0; i < k; i++) {
    if (s[i] == '1') one++;
    if (s[i] == '0') zero++;
  }
  int question = k - (one + zero);
  int f1 = k / 2 - one, f0 = k / 2 - zero;
  if (f1 < 0 || f0 < 0 || f1 + f0 != question) pos = 0;
  if (pos)
    cout << "YES";
  else
    cout << "NO";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  for (int nc = 1; nc < t + 1; nc++) solve();
  return 0;
}
