#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const long long Mod = 1e9 + 7;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= Mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % Mod;
    a = a * a % Mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int T;
int n, k;
int mo[maxn];
char st[maxn];
int main() {
  scanf("%d", &T);
  for (int cas = 1; cas <= T; ++cas) {
    scanf("%d%d", &n, &k);
    scanf("%s", st);
    bool bo = true;
    for (int i = 1; i <= n; ++i) {
      if (i <= k) mo[i % k + 1] = 0;
      if (st[i - 1] == '1') {
        if (mo[i % k + 1] >= 0) {
          mo[i % k + 1] = 1;
        } else {
          bo = false;
          break;
        }
      }
      if (st[i - 1] == '0') {
        if (mo[i % k + 1] <= 0) {
          mo[i % k + 1] = -1;
        } else {
          bo = false;
          break;
        }
      }
    }
    if (!bo) {
      puts("NO");
      continue;
    }
    int sum_min = 0, sum_max = 0;
    for (int i = 1; i <= k; i++) {
      if (mo[i] == 1)
        sum_max++, sum_min++;
      else if (mo[i] == -1)
        sum_max--, sum_min--;
      else
        sum_max++, sum_min--;
    }
    if (sum_max >= 0 && sum_min <= 0)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
