#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c != '-' && c < 48) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c > 47) x = x * 10 + (c ^ 48), c = getchar();
  return f * x;
}
const int maxn = 3e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, k;
char s[maxn];
void solve() {
  n = read(), k = read();
  scanf("%s", s + 1);
  for (int i = 1; i <= k; ++i) {
    int f = 2;
    for (int j = i; j <= n; j += k) {
      if (s[j] == '0' && f == 1) return (void)printf("NO\n");
      if (s[j] == '1' && f == 0) return (void)printf("NO\n");
      if (s[j] == '0') f = 0;
      if (s[j] == '1') f = 1;
    }
    if (f == 0) s[i] = '0';
    if (f == 1) s[i] = '1';
  }
  int c0 = 0, c1 = 0, c2 = 0;
  for (int i = 1; i <= k; ++i) {
    if (s[i] == '0')
      c0++;
    else if (s[i] == '1')
      c1++;
    else
      c2++;
  }
  if (abs(c0 - c1) > c2)
    printf("NO\n");
  else
    printf("YES\n");
}
int main() {
  int T = read();
  while (T--) solve();
}
