#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int net = 0, que = 0, flag = 1;
    for (int i = 0; i < k; i++) {
      int one = 0, zero = 0;
      int j = i;
      while (j < n) {
        if (s[j] == '1') one++;
        if (s[j] == '0') zero++;
        j += k;
      }
      if (one == 0 && zero == 0) que++;
      if (one != 0 && zero != 0) flag = 0;
      if (one != 0) net++;
      if (zero != 0) net--;
    }
    if (flag) {
      if (net == 0) {
        if (que % 2 == 0)
          cout << "YES\n";
        else
          cout << "NO\n";
      } else {
        if ((que) >= abs(net) && (que - abs(net)) % 2 == 0)
          cout << "YES\n";
        else
          cout << "NO\n";
      }
    } else
      cout << "NO\n";
  }
}
