#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e18;
int main() {
  long long b, c, d, i, j, k, l, n, x, y, t, ans, st;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    string s;
    cin >> s;
    long long must[k], flag = 0, zero = 0, one = 0;
    memset(must, -1, sizeof(must));
    for (i = 0; i < n; i++) {
      if (s[i] == '0' || s[i] == '1') {
        long long a = s[i] - '0';
        if (must[i % k] == -1)
          must[i % k] = a;
        else {
          if (must[i % k] != a) {
            flag = 1;
            break;
          }
        }
      }
    }
    if (flag == 0) {
      for (i = 0; i < k; i++) {
        if (must[i] == 0)
          zero++;
        else if (must[i] == 1)
          one++;
      }
      long long lim = k / 2;
      if (zero <= lim && one <= lim)
        flag = 0;
      else
        flag = 1;
    }
    if (flag)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
