#include <bits/stdc++.h>
using namespace std;
const int NN = 303030;
char s[NN];
char ans[NN];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    scanf("%s", s + 1);
    int flag = 1;
    for (int i = 1; i <= n; i++) {
      if (i <= k)
        ans[i] = s[i];
      else {
        int u = (i - 1) % k + 1;
        if (ans[u] != '?' and s[i] != '?' and ans[u] != s[i]) {
          flag = 0;
        } else if (s[i] != '?') {
          ans[u] = s[i];
        }
      }
    }
    int a = 0, b = 0;
    for (int i = 1; i <= k; i++) {
      if (ans[i] == '0')
        a++;
      else if (ans[i] == '1')
        b++;
    }
    if (max(a, b) * 2 > k) flag = 0;
    if (flag)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
