#include <bits/stdc++.h>
using namespace std;
long long test, n, a[100001], k;
bool check(string s) {
  int cnt0 = 0, cnt1 = 0, cnt = 0;
  for (int i = 0; i < k; i++) {
    int ok1 = 0, ok0 = 0;
    for (int j = i; j < n; j += k) {
      if (s[j] == '1')
        ok1 = 1;
      else if (s[j] == '0')
        ok0 = 1;
      if (ok1 && ok0) return false;
    }
    if (ok1)
      cnt1++;
    else if (ok0)
      cnt0++;
    else
      cnt++;
  }
  if ((cnt - abs(cnt1 - cnt0)) % 2 != 0 || (cnt - abs(cnt1 - cnt0)) < 0)
    return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> test;
  while (test--) {
    cin >> n >> k;
    string s;
    cin >> s;
    if (check(s))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
