#include <bits/stdc++.h>
using namespace std;
mt19937_64 mrand(42);
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int ok = 1;
    for (int i = 0; i < k; ++i) {
      int c0 = 0, c1 = 0;
      for (int j = i; j < n; j += k) {
        if (s[j] == '0')
          c0++;
        else if (s[j] == '1')
          c1++;
      }
      if (c0 && c1) {
        ok = 0;
        break;
      }
      if (c0)
        for (int j = i; j < n; j += k) s[j] = '0';
      else if (c1)
        for (int j = i; j < n; j += k) s[j] = '1';
    }
    int c1 = 0, c0 = 0;
    for (int i = 0; i < k; ++i)
      if (s[i] == '1')
        c1++;
      else if (s[i] == '0')
        c0++;
    if (c1 > k / 2 || c0 > k / 2 || !ok) {
      cout << "NO" << endl;
      continue;
    } else
      cout << "YES" << endl;
  }
}
