#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    int n, k, flag = 0;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<char> v;
    unordered_map<char, int> mp;
    for (int i = 0; i < k; i++) {
      mp[s[i]]++;
    }
    if (mp['0'] > k / 2 || mp[1] > k / 2) flag = 1;
    if (flag)
      cout << "NO\n";
    else {
      for (int i = 0; i < k; i++) {
        int q = 0, z = 0, o = 0;
        for (int j = i; j < n; j += k) {
          if (s[j] == '?')
            q++;
          else if (s[j] == '0')
            z++;
          else
            o++;
        }
        if (z > 0 && o > 0) {
          flag = 1;
          break;
        }
        if (z > 0)
          v.push_back('0');
        else if (o > 0)
          v.push_back('1');
        else
          v.push_back('?');
      }
      if (flag)
        cout << "NO\n";
      else {
        unordered_map<char, int> hola;
        for (auto i : v) {
          hola[i]++;
        }
        if (hola['0'] > k / 2 || hola['1'] > k / 2)
          cout << "NO\n";
        else
          cout << "YES\n";
      }
    }
  }
}
