#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < k; i++) {
    int a = 0, b = 0, c = 0;
    for (int j = i; j < n; j += k) {
      if (s[j] == '1')
        a++;
      else if (s[j] == '0')
        b++;
      else
        c++;
    }
    if (a > 0 and b > 0) {
      cout << "NO" << endl;
      return;
    } else if (a > 0) {
      for (int j = i; j < n; j += k) {
        s[j] = '1';
      }
    } else if (b > 0) {
      for (int j = i; j < n; j += k) {
        s[j] = '0';
      }
    }
  }
  int a = 0, b = 0, c = 0;
  for (int i = 0; i < k; i++) {
    if (s[i] == '1')
      a++;
    else if (s[i] == '0')
      b++;
  }
  if (a > k / 2 or b > k / 2) {
    cout << "NO" << endl;
    return;
  }
  for (int i = k; i < n; i++) {
    if (s[i - k] == '1')
      a--;
    else if (s[i - k] == '0')
      b--;
    if (s[i] == '1')
      a++;
    else if (s[i] == '0')
      b++;
    if (a > k / 2 or b > k / 2) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long qu = 1;
  cin >> qu;
  while (qu--) {
    solve();
  }
}
