#include <bits/stdc++.h>
using namespace std;
const int N = 300300;
string Read() {
  static char Buffer[N];
  scanf("%s", Buffer);
  return Buffer;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    scanf("%d%d", &n, &k);
    string s = Read();
    vector<vector<int>> Cnt(k, vector<int>(2));
    for (int i = 0; i < n; i++)
      if (s[i] != '?') Cnt[i % k][s[i] - '0']++;
    bool Ok = true;
    for (int i = 0; i < k; i++)
      if (Cnt[i][0] && Cnt[i][1]) Ok = false;
    vector<int> Cnt2(2);
    for (int i = 0; i < k; i++) {
      if (Cnt[i][0]) Cnt2[0]++;
      if (Cnt[i][1]) Cnt2[1]++;
    }
    if (Cnt2[0] > k / 2) Ok = false;
    if (Cnt2[1] > k / 2) Ok = false;
    puts(Ok ? "YES" : "NO");
  }
}
