#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
long long poww(long long a, long long b) {
  if (b == 0) return 1;
  long long x = poww(a, b / 2);
  x = x * x;
  if (b % 2 == 1) x = x * a;
  return x;
}
long long bigmod(long long a, long long b, long long c) {
  if (b == 0) return 1 % c;
  long long x = bigmod(a, b / 2, c);
  x = x * x % c;
  if (b % 2 == 1) x = x * a % c;
  return x;
}
long long mod_inverse(long long a, long long mod) {
  return bigmod(a, mod - 2, mod);
}
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    cin >> s;
    int x = 0, y = 0, z = 0;
    bool flg = 0;
    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] == '0') a++;
        if (s[j] == '1') b++;
        if (s[j] == '?') c++;
      }
      if (a && b) {
        flg = 1;
        break;
      }
      if (c && !a && !b)
        z++;
      else if (a)
        x++;
      else if (b)
        y++;
    }
    if (flg)
      cout << "NO" << endl;
    else {
      if (x > y) swap(x, y);
      if (x + z >= y)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}
