#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
char s[int(3e5 + 5)];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    cin >> (s + 1);
    bool flag = true;
    int tmp1 = 0, tmp = 0;
    for (int i = 1; i <= m; i++)
      if (s[i] == '1')
        tmp1++;
      else if (s[i] == '?')
        tmp++;
    if (tmp1 + tmp < m / 2 or tmp1 > m / 2) flag = false;
    for (int i = 1; i <= m and flag == true; i++) {
      char ch = '?';
      for (int j = i; j <= n and flag == true; j += m) {
        if (s[j] == '?') continue;
        if (ch == '?')
          ch = s[j];
        else {
          if (ch == s[j])
            continue;
          else
            flag = false;
        }
      }
      if (flag == true)
        for (int j = i; j <= n; j += m) s[j] = ch;
    }
    tmp1 = tmp = 0;
    for (int i = 1; i <= m; i++)
      if (s[i] == '1')
        tmp1++;
      else if (s[i] == '?')
        tmp++;
    if (tmp1 + tmp < m / 2 or tmp1 > m / 2) flag = false;
    if (flag == true)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
