#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int m_inf = INT_MIN;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<char> dp(k);
    int zero = 0, one = 0, neutral = 0;
    bool flag = true;
    for (int i = 0; i < k; i++) {
      dp[i] = s[i];
      for (int j = i + k; j < n; j += k) {
        if (s[j] == '?') continue;
        if (s[j] == '1') {
          if (dp[i] == '0') {
            flag = false;
            break;
          }
          dp[i] = '1';
        } else {
          if (dp[i] == '1') {
            flag = false;
            break;
          }
          dp[i] = '0';
        }
      }
      if (!flag) break;
    }
    for (int i = 0; i < k; i++) {
      if (dp[i] == '0')
        zero++;
      else if (dp[i] == '1')
        one++;
      else
        neutral++;
    }
    if (zero > k / 2 || one > k / 2) flag = false;
    if (flag)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
}
