#include <bits/stdc++.h>
using namespace std;
bool func(string s, int n, int k) {
  int i, j;
  for (i = 0; i < k; i++) {
    char c = '?';
    for (j = i; j < n; j += k) {
      if (s[j] == '1' && c == '0') return false;
      if (s[j] == '0' && c == '1') return false;
      if (s[j] != '?') c = s[j];
    }
    for (j = i; j < n; j += k) {
      s[j] = c;
    }
  }
  int x = 0, y = 0, z = 0;
  for (i = 0; i < k; i++) {
    if (s[i] == '1') {
      x++;
    } else if (s[i] == '0') {
      y++;
    } else {
      z++;
    }
  }
  if (z < abs(y - x) || (z - abs(y - x)) % 2 != 0) return false;
  return true;
}
int main() {
  long long int t, mod = (1e+9) + 7;
  cin >> t;
  while (t != 0) {
    int n, k, j, i;
    cin >> n >> k;
    string s;
    cin >> s;
    if (func(s, n, k))
      cout << "YES" << endl;
    else {
      cout << "NO" << endl;
    }
    t--;
  }
}
