#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    bool can = 1;
    for (int i = 0; i < k; i++) {
      char t = '?';
      for (int j = i; j < s.size(); j += k) {
        if (s[j] != '?' && t == '?')
          t = s[j];
        else if (t != '?' && s[j] != '?' && t != s[j]) {
          can = 0;
          break;
        }
      }
      if (t != '?') {
        for (int j = i; j < s.size(); j += k) s[j] = t;
      }
    }
    int one = 0, zero = 0, wen = 0;
    for (int i = 0; i < k; i++)
      if (s[i] == '?')
        wen++;
      else if (s[i] == '0')
        zero++;
      else
        one++;
    int cha = abs(zero - one);
    if (wen < cha) can = 0;
    if (can)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
