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