#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define w(x) ll x; cin>>x; while(x--)
#define mod 1000000007;
using namespace std;
void cp()
{
    //ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
}
ll po(ll x, ll y)
{
    ll res = 1;

    while (y > 0)
    {
        if (y & 1)
            res = res*x;

        y = y>>1;
        x = x*x;
    }
    return res;
}
ll fs(ll arr[], ll n, ll sum)
{

    unordered_map<ll, ll> prevSum;

    ll res = 0;
    ll currsum = 0;

    for (ll i = 0; i < n; i++) {

        currsum += arr[i];
        if (currsum == sum)
            res++;

        if (prevSum.find(currsum - sum) !=
                                  prevSum.end())
            res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }

    return res;
}
ll fac(ll n)
{
    ll i,k;
    if(n==0)
    return 1;
    else if(n==1)
    return 1;
    else
    return n*fac(n-1);
}
int main()
{
    cp();
    ll t;
    cin>>t;
    while(t--)
    {
      ll n,x=0,y=0,c=0,k,i,j,z=0,f=0,q=0,r=0;
      cin>>n>>k;
      string s;
      cin>>s;
      for(i=0;i<k;i++)
      {
          if(s[i]=='?')
          c++;
          else if(s[i]=='1')
          x++;
          else
          y++;
      }
      if(x>k/2 || y>k/2)
      {
          cout<<"NO"<<endl;
          continue;
      }
      if (c==0)
      {
          goto next;
      }
      else
      {
          if(x==k/2)
          {
              for(i=0;i<k;i++)
              {
                  if(s[i]=='?')
                  s[i]='0';
              }
          }
          else if(y==k/2)
          {
              for(i=0;i<k;i++)
              {
                  if(s[i]=='?')
                  s[i]='1';
              }
          }
          else
          {
              for(i=0;i<k;i++)
              {
                  if(s[i]=='?')
                  {
                      if((i+k)<n )
                      {
                          if(s[i+k]=='1')
                          s[i]='1';
                          else if(s[i+k]=='0')
                          s[i]='0';
                      }
                  }
              }
              x=0,y=0;
    for(i=0;i<k;i++)
      {
         if(s[i]=='1')
          x++;
          else
          y++;
      }
      ll x1=k/2-x;
      ll y1=k/2-y;
      for(i=0;i<k;i++)
      {
          if(s[i]=='?')
          {
              if(x1>0)
              {s[i]='1';
              x1--;}
              else
              {
                  s[i]='0';
                  y1--;
              }

          }

      }

          }

      }
      next:
      //cout<<s<<endl;
      for(i=k;i<n;i++)
      {
          //cout<<i<<s[i]<<s[z]<<z<<endl;
          if(s[i]=='?')
          {
              s[i]=s[z];
          }
          else if(s[i]==s[z])
          {
              z++;
              continue;
          }
          else
          {
              f=1;
              break;
          }
          z++;
      }
      if(f==1)
      cout<<"NO"<<endl;
      else
      {
        cout<<"YES"<<endl;
      }
      //for(i=0;i<k;i++)
      //cout<<s[i];
      //cout<<endl;
  }

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define t ll t; cin>>t; while(t--)
#define mod 1000000007;
#define f(i,n) for(i=0;i<n;i++)
#define fo(i,n) for(i=1;i<n;i++)
using namespace std;
void cp()
{
    //ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
}
ll po(ll x, ll y)
{
    ll res = 1;

    while (y > 0)
    {
        if (y & 1)
            res = res*x;

        y = y>>1;
        x = x*x;
    }
    return res;
}
ll fs(ll arr[], ll n, ll sum)
{

    unordered_map<ll, ll> prevSum;

    ll res = 0;
    ll currsum = 0;

    for (ll i = 0; i < n; i++) {

        currsum += arr[i];
        if (currsum == sum)
            res++;

        if (prevSum.find(currsum - sum) !=
                                  prevSum.end())
            res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }

    return res;
}
ll fac(ll n)
{
    ll i,k;
    if(n==0)
    return 1;
    else if(n==1)
    return 1;
    else
    return n*fac(n-1);
}
/*vector<ll> find(ll a[],ll k,ll n)
{

    int s=0;
    int e=n-1;
    while (s<=e){
        int mid=(s+e)/2;

        if(a[mid]==key){
            return 1;
        }
        if (a[mid]>key){
            e=mid-1;
        }
        else{
            s=mid+1;
        }
    }
}*/
int main()
{
    cp();
    t{
    ll n,c=0,i,k,j,y=0,m,z=0,x=0;
    vector<ll> v;
    //map<ll,ll> p;
    string s;
    cin>>n>>k>>s;
    for(i=0;i<k;i++)
    {
        for(j=i;j<n;j+=k)
        {
            if(s[i]=='?')
            {
                s[i]=s[j];
            }
            else
            {
                if(s[j]=='?')
                s[j]=s[i];
                else if(s[i]!=s[j])
                {
                   // cout<<s[j]<<" "<<s[i]<<endl;;
                    z=1;
                    break;
                }
            }

        }
        if(z==1)
        break;
    }
    if(z==1)
    {
        cout<<"NO"<<endl;
        continue;
    }
    for(i=0;i<k;i++)
    {
        if(s[i]=='1')
        c++;
        if(s[i]=='0')
        x++;
    }
    c=k/2-c;
    x=k/2-c;
    if(c==0 && x==0)
    {
        ll goat=0;
    }
    else
    {
        for(i=0;i<k;i++)
        {
            if(s[i]=='?')
            {
                if(c>0)
                {
                    s[i]='1';
                    c--;
                }
                else
                {
                    s[i]='0';
                    x--;
                }
            }
        }
    for(i=0;i<k;i++)
    {
        for(j=i;j<n;j+=k)
        {
            s[j]=s[i];
        }
    }
    }
    c=0,x=0;
    for(i=0;i<k;i++)
    {
        if(s[i]=='1')
        c++;
        if(s[i]=='0')
        x++;
    }
    if(c==k/2 && x==k/2)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define w(x) ll x; cin>>x; while(x--)
#define mod 1000000007;
using namespace std;
void cp()
{
    //ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
}
ll po(ll x, ll y)
{
    ll res = 1;

    while (y > 0)
    {
        if (y & 1)
            res = res*x;

        y = y>>1;
        x = x*x;
    }
    return res;
}
ll fs(ll arr[], ll n, ll sum)
{

    unordered_map<ll, ll> prevSum;

    ll res = 0;
    ll currsum = 0;

    for (ll i = 0; i < n; i++) {

        currsum += arr[i];
        if (currsum == sum)
            res++;

        if (prevSum.find(currsum - sum) !=
                                  prevSum.end())
            res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }

    return res;
}
ll fac(ll n)
{
    ll i,k;
    if(n==0)
    return 1;
    else if(n==1)
    return 1;
    else
    return n*fac(n-1);
}
int main()
{
    cp();
    ll t;
    cin>>t;
    while(t--)
    {
      ll n,x=0,y=0,c,k,i,j,z=0,f=0,q=0,r=0;
      cin>>n>>k;
      string s;
      cin>>s;
      for(i=0;i<k;i++)
      {
          if(s[i]=='?')
          c++;
          else if(s[i]=='1')
          x++;
          else
          y++;
      }
      if(x>k/2 || y>k/2)
      {
          cout<<"NO"<<endl;
          continue;
      }
      if (c==0)
      {
          goto next;
      }
      else
      {
          if(x==k/2)
          {
              for(i=0;i<k;i++)
              {
                  if(s[i]=='?')
                  s[i]='0';
              }
          }
          else if(y==k/2)
          {
              for(i=0;i<k;i++)
              {
                  if(s[i]=='?')
                  s[i]='1';
              }
          }
          else
          {
              for(i=0;i<k;i++)
              {
                  if(s[i]=='?')
                  {
                      if((i+k)<n )
                      {
                          if(s[i+k]=='1')
                          s[i]='1';
                          else if(s[i]=='0')
                          s[i]='0';
                      }
                  }
              }
              x=0,y=0;
    for(i=0;i<k;i++)
      {
         if(s[i]=='1')
          x++;
          else
          y++;
      }
      ll x1=k/2-x;
      ll y1=k/2-y;
      for(i=0;i<k;i++)
      {
          if(s[i]=='?')
          {
              if(x1>0)
              {s[i]='1';
              x1--;}
              else
              {
                  s[i]='0';
                  y1--;
              }

          }

      }

          }

      }
      next:
      for(i=k;i<n;i++)
      {
          //cout<<i<<s[i]<<s[z]<<z<<endl;
          if(s[i]=='?')
          {
              s[i]=s[z];
          }
          else if(s[i]==s[z])
          {
              z++;
              continue;
          }
          else
          {
              f=1;
              break;
          }
          z++;
      }
      if(f==1)
      cout<<"NO"<<endl;
      else
      {
        cout<<"YES"<<endl;
      }
      //for(i=0;i<k;i++)
      //cout<<s[i];
      //cout<<endl;
  }

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define w(x) ll x; cin>>x; while(x--)
#define mod 1000000007;
using namespace std;
void cp()
{
    //ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
}
ll po(ll x, ll y)
{
    ll res = 1;

    while (y > 0)
    {
        if (y & 1)
            res = res*x;

        y = y>>1;
        x = x*x;
    }
    return res;
}
ll fs(ll arr[], ll n, ll sum)
{

    unordered_map<ll, ll> prevSum;

    ll res = 0;
    ll currsum = 0;

    for (ll i = 0; i < n; i++) {

        currsum += arr[i];
        if (currsum == sum)
            res++;

        if (prevSum.find(currsum - sum) !=
                                  prevSum.end())
            res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }

    return res;
}
ll fac(ll n)
{
    ll i,k;
    if(n==0)
    return 1;
    else if(n==1)
    return 1;
    else
    return n*fac(n-1);
}
int main()
{
    cp();
    ll t;
    cin>>t;
    while(t--)
    {
      ll n,x=0,y=0,c,k,i,j,z=0,f=0;
      cin>>n>>k;
      string s;
      cin>>s;
      for(i=0;i<k;i++)
      {
          if(s[i]=='?')
          c++;
          else if(s[i]=='1')
          x++;
          else
          y++;
      }
      if(x>k/2 || y>k/2)
      {
          cout<<"NO"<<endl;
          continue;
      }
      if (c==0)
      {
          goto next;
      }
      else
      {
          if(x==k/2)
          {
              for(i=0;i<k;i++)
              {
                  if(s[i]=='?')
                  s[i]='0';
              }
          }
          else if(y==k/2)
          {
              for(i=0;i<k;i++)
              {
                  if(s[i]=='?')
                  s[i]='1';
              }
          }
          else
          {
              for(i=0;i<k;i++)
              {
                  if(s[i]=='?')
                  {
                      if(i+k<n )
                      {
                          if(s[i+k]=='1')
                          s[i]=='1';
                          else if(s[i]=='0')
                          s[i]='0';
                      }
                  }
              }
              x=0,y=0;
    for(i=0;i<k;i++)
      {
         if(s[i]=='1')
          x++;
          else
          y++;
      }
      ll x1=k/2-x;
      ll y1=k/2-y;
      for(i=0;i<k;i++)
      {
          if(s[i]=='?')
          {
              if(x1>0)
              {s[i]='1';
              x1--;}
              else
              {
                  s[i]='0';
                  y1--;
              }

          }

      }

          }

      }
      next:
      for(i=k;i<n;i++)
      {
          //cout<<i<<s[i]<<s[z]<<z<<endl;
          if(s[i]=='?')
          {
              s[i]=s[z];
          }
          else if(s[i]==s[z])
          {
              z++;
              continue;
          }
          else
          {
              f=1;
              break;
          }
          z++;
      }
      if(f==1)
      cout<<"NO"<<endl;
      else
      cout<<"YES"<<endl;
      //for(i=0;i<k;i++)
      //cout<<s[i];
      //cout<<endl;
  }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
// int digit(int n)
// {
// 	int c=0;
// 	while(n!=0)
// 	{
// 		c++;
// 		n=n/10;
// 	}
// 	return c;
// }
// bool check(vector<int> a,vector<int> b)
// {
// 	for(int i=0;i<4;i++)
// 	{
// 		int flag=1;
// 		for(int j=0;j<4;j++)
// 		{
// 			if(a[(i+j)%4]!=b[j])
// 			{
// 				flag=0;
// 				break;
// 			}
// 		}
// 		if(flag==1)
// 			return true;
// 	}
// 	return false;
// }
// bool comp(pair<int,int>>a,vector<pair<int,int>>b)
// {
// 	return(a.first<b.first);
// }
// sort(a.begin(),a.end(),greater<int>());
// priority_queue<int, vector<int>, greater<int> > Q;
// int gcd(ll a, ll b)
// {
//     if (b == 0)
//         return a;
//     return gcd(b, a % b);

// }
// ll mod=1000000007;
// ll power(ll a, ll b){
// 	ll x = 1, y = a;
// 	while (b > 0){
// 		if (b%2){
// 			x = (x*y)%mod;
// 		}
// 		y = (y*y)%mod;
// 		b /= 2;
// 	}
// 	return x%mod;
// }
// ll modular_inverse(ll n){
// 	return power(n, mod-2);
// }
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t;
	cin>>t;
	// t=1;
	for(ll f=0;f<t;f++)
	{
		ll n,k;
		cin>>n>>k;
		string A;
		cin>>A;
		ll i;
		ll l=0;
		ll r=k-1;
		ll c0=0,c1=0,c2=0;
		for(i=0;i<n;i++)
		{
			if(A[i]=='1')
				c1++;
			else if(A[i]=='0')
				c0++;
			else
				c2++;
		}
		if(c0==0 && c1==0)
		{
			cout<<"YES"<<endl;
			continue;
		}
		int flag=1;
		for(i=0;i+k<n;i++)
		{
			if(A[i]=='0')
			{
				if(A[i+k]=='1')
				{
					flag=0;
					break;
				}
				if(A[i+k]=='0')
					continue;
				A[i+k]='0';
			}
			if(A[i]=='1')
			{
				if(A[i+k]=='0')
				{
					flag=0;
					break;
				}
				if(A[i+k]=='1')
					continue;
				A[i+k]='1';
			}
			if(A[i]=='?')
			{
				if(A[i+k]=='0')
				{
					A[i]='0';
				}
				if(A[i+k]=='1')
					A[i]='1';
			}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		for(i=n-1;i-k>=0;i--)
		{

		}
		for(i=0;i+k<n;i++)
		{
			if(A[i]!=A[i+k])
			{
				flag=0;
				break;
			}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		// cout<<"YES"<<endl;
		c1=0;
		c2=0;
		c0=0;
		for(i=0;i<k;i++)
		{
			if(A[i]=='1')
				c1++;
			else if(A[i]=='0')
				c0++;
			else
				c2++;
		}
		if(abs(c1-c0)>c2)
		{
			cout<<"NO"<<endl;
			continue;
		}
		// cout<<"YES"<<endl;
		while(r+1<n)
		{
			if(A[l]=='0')
				c0--;
			if(A[l]=='1')
				c1--;
			if(A[l]=='?')
				c2--;
			if(A[r+1]=='0')
				c0++;
			if(A[r+1]=='1')
				c1++;
			if(A[r+1]=='?')
				c2++;
			l++;
			r++;
			if(abs(c1-c0)>c2)
		{
			flag=0;
			break;
		}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		cout<<"YES"<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
// int digit(int n)
// {
// 	int c=0;
// 	while(n!=0)
// 	{
// 		c++;
// 		n=n/10;
// 	}
// 	return c;
// }
// bool check(vector<int> a,vector<int> b)
// {
// 	for(int i=0;i<4;i++)
// 	{
// 		int flag=1;
// 		for(int j=0;j<4;j++)
// 		{
// 			if(a[(i+j)%4]!=b[j])
// 			{
// 				flag=0;
// 				break;
// 			}
// 		}
// 		if(flag==1)
// 			return true;
// 	}
// 	return false;
// }
// bool comp(pair<int,int>>a,vector<pair<int,int>>b)
// {
// 	return(a.first<b.first);
// }
// sort(a.begin(),a.end(),greater<int>());
// priority_queue<int, vector<int>, greater<int> > Q;
// int gcd(ll a, ll b)
// {
//     if (b == 0)
//         return a;
//     return gcd(b, a % b);

// }
// ll mod=1000000007;
// ll power(ll a, ll b){
// 	ll x = 1, y = a;
// 	while (b > 0){
// 		if (b%2){
// 			x = (x*y)%mod;
// 		}
// 		y = (y*y)%mod;
// 		b /= 2;
// 	}
// 	return x%mod;
// }
// ll modular_inverse(ll n){
// 	return power(n, mod-2);
// }
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t;
	cin>>t;
	// t=1;
	for(ll f=0;f<t;f++)
	{
		ll n,k;
		cin>>n>>k;
		string A;
		cin>>A;
		ll i;
		ll l=0;
		ll r=k-1;
		ll c0=0,c1=0,c2=0;
		for(i=0;i<n;i++)
		{
			if(A[i]=='1')
				c1++;
			else if(A[i]=='0')
				c0++;
			else
				c2++;
		}
		if(c0==0 && c1==0)
		{
			cout<<"YES"<<endl;
			continue;
		}
		int flag=1;
		for(i=0;i+k<n;i++)
		{
			if(A[i]=='0')
			{
				if(A[i+k]=='1')
				{
					flag=0;
					break;
				}
				if(A[i+k]=='0')
					continue;
				A[i+k]='0';
			}
			if(A[i]=='1')
			{
				if(A[i+k]=='0')
				{
					flag=0;
					break;
				}
				if(A[i+k]=='1')
					continue;
				A[i+k]='1';
			}
			if(A[i]=='?')
			{
				if(A[i+k]=='0')
				{
					A[i]='0';
				}
				if(A[i+k]=='1')
					A[i]='1';
			}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		for(i=n-1;i-k>=0;i--)
		{

		}
		for(i=0;i+k<n;i++)
		{
			if(A[i]!=A[i+k])
			{
				flag=0;
				break;
			}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		// cout<<"YES"<<endl;
		c1=0;
		c2=0;
		c0=0;
		for(i=0;i<k;i++)
		{
			if(A[i]=='1')
				c1++;
			else if(A[i]=='0')
				c0++;
			else
				c2++;
		}
		if(c1>k/2 || c0>k/2)
		{
			cout<<"NO"<<endl;
			continue;
		}
		// cout<<"YES"<<endl;
		while(r+1<n)
		{
			if(A[l]=='0')
				c0--;
			if(A[l]=='1')
				c1--;
			if(A[r+1]=='0')
				c0++;
			if(A[r+1]=='1')
				c1++;
			l++;
			r++;
			if(c1>k/2 || c0>k/2)
		{
			flag=0;
			break;
		}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		cout<<"YES"<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
// int digit(int n)
// {
// 	int c=0;
// 	while(n!=0)
// 	{
// 		c++;
// 		n=n/10;
// 	}
// 	return c;
// }
// bool check(vector<int> a,vector<int> b)
// {
// 	for(int i=0;i<4;i++)
// 	{
// 		int flag=1;
// 		for(int j=0;j<4;j++)
// 		{
// 			if(a[(i+j)%4]!=b[j])
// 			{
// 				flag=0;
// 				break;
// 			}
// 		}
// 		if(flag==1)
// 			return true;
// 	}
// 	return false;
// }
// bool comp(pair<int,int>>a,vector<pair<int,int>>b)
// {
// 	return(a.first<b.first);
// }
// sort(a.begin(),a.end(),greater<int>());
// priority_queue<int, vector<int>, greater<int> > Q;
// int gcd(ll a, ll b)
// {
//     if (b == 0)
//         return a;
//     return gcd(b, a % b);

// }
// ll mod=1000000007;
// ll power(ll a, ll b){
// 	ll x = 1, y = a;
// 	while (b > 0){
// 		if (b%2){
// 			x = (x*y)%mod;
// 		}
// 		y = (y*y)%mod;
// 		b /= 2;
// 	}
// 	return x%mod;
// }
// ll modular_inverse(ll n){
// 	return power(n, mod-2);
// }
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t;
	cin>>t;
	// t=1;
	for(ll f=0;f<t;f++)
	{
		ll n,k;
		cin>>n>>k;
		string A;
		cin>>A;
		ll i;
		ll l=0;
		ll r=k-1;
		ll c0=0,c1=0,c2=0;
		for(i=0;i<n;i++)
		{
			if(A[i]=='1')
				c1++;
			else if(A[i]=='0')
				c0++;
			else
				c2++;
		}
		if(c0==0 && c1==0)
		{
			cout<<"YES"<<endl;
			continue;
		}
		int flag=1;
		for(i=0;i+k<n;i++)
		{
			if(A[i]=='0')
			{
				if(A[i+k]=='1')
				{
					flag=0;
					break;
				}
				if(A[i+k]=='0')
					continue;
				A[i+k]='0';
			}
			if(A[i]=='1')
			{
				if(A[i+k]=='0')
				{
					flag=0;
					break;
				}
				if(A[i+k]=='1')
					continue;
				A[i+k]='1';
			}
			if(A[i]=='?')
			{
				if(A[i+k]=='0')
				{
					A[i]='0';
				}
				if(A[i+k]=='1')
					A[i]='1';
			}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		// for(i=0;i+k<n;i++)
		// {
		// 	if(A[i]!=A[i+k])
		// 	{
		// 		flag=0;
		// 		break;
		// 	}
		// }
		// if(flag==0)
		// {
		// 	cout<<"NO"<<endl;
		// 	continue;

		// cout<<"YES"<<endl;
		c1=0;
		c2=0;
		c0=0;
		for(i=0;i<k;i++)
		{
			if(A[i]=='1')
				c1++;
			else if(A[i]=='0')
				c0++;
			else
				c2++;
		}
		if(abs(c1-c0)>c2)
		{
			cout<<"NO"<<endl;
			continue;
		}
		// cout<<"YES"<<endl;
		while(r+1<n)
		{
			if(A[l]=='0')
				c0--;
			if(A[l]=='1')
				c1--;
			if(A[l]=='?')
				c2--;
			if(A[r+1]=='0')
				c0++;
			if(A[r+1]=='1')
				c1++;
			if(A[r+1]=='?')
				c2++;
			l++;
			r++;
			if(abs(c1-c0)>c2)
		{
			flag=0;
			break;
		}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		cout<<"YES"<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
// int digit(int n)
// {
// 	int c=0;
// 	while(n!=0)
// 	{
// 		c++;
// 		n=n/10;
// 	}
// 	return c;
// }
// bool check(vector<int> a,vector<int> b)
// {
// 	for(int i=0;i<4;i++)
// 	{
// 		int flag=1;
// 		for(int j=0;j<4;j++)
// 		{
// 			if(a[(i+j)%4]!=b[j])
// 			{
// 				flag=0;
// 				break;
// 			}
// 		}
// 		if(flag==1)
// 			return true;
// 	}
// 	return false;
// }
// bool comp(pair<int,int>>a,vector<pair<int,int>>b)
// {
// 	return(a.first<b.first);
// }
// sort(a.begin(),a.end(),greater<int>());
// priority_queue<int, vector<int>, greater<int> > Q;
// int gcd(ll a, ll b)
// {
//     if (b == 0)
//         return a;
//     return gcd(b, a % b);

// }
// ll mod=1000000007;
// ll power(ll a, ll b){
// 	ll x = 1, y = a;
// 	while (b > 0){
// 		if (b%2){
// 			x = (x*y)%mod;
// 		}
// 		y = (y*y)%mod;
// 		b /= 2;
// 	}
// 	return x%mod;
// }
// ll modular_inverse(ll n){
// 	return power(n, mod-2);
// }
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t;
	cin>>t;
	// t=1;
	for(ll f=0;f<t;f++)
	{
		ll n,k;
		cin>>n>>k;
		string A;
		cin>>A;
		ll i;
		ll l=0;
		ll r=k-1;
		ll c0=0,c1=0,c2=0;
		for(i=0;i<n;i++)
		{
			if(A[i]=='1')
				c1++;
			else if(A[i]=='0')
				c0++;
			else
				c2++;
		}
		if(c0==0 && c1==0)
		{
			cout<<"YES"<<endl;
			continue;
		}
		int flag=1;
		for(i=0;i+k<n;i++)
		{
			if(A[i]=='0')
			{
				if(A[i+k]=='1')
				{
					flag=0;
					break;
				}
				if(A[i+k]=='0')
					continue;
				A[i+k]='0';
			}
			if(A[i]=='1')
			{
				if(A[i+k]=='0')
				{
					flag=0;
					break;
				}
				if(A[i+k]=='1')
					continue;
				A[i+k]='1';
			}
			if(A[i]=='?')
			{
				if(A[i+k]=='0')
				{
					A[i]='0';
				}
				if(A[i+k]=='1')
					A[i]='1';
			}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		for(i=n-1;i-k>=0;i--)
		{

		}
		for(i=0;i+k<n;i++)
		{
			if(A[i]!=A[i+k])
			{
				flag=0;
				break;
			}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		// cout<<"YES"<<endl;
		c1=0;
		c2=0;
		c0=0;
		for(i=0;i<k;i++)
		{
			if(A[i]=='1')
				c1++;
			else if(A[i]=='0')
				c0++;
			else
				c2++;
		}
		if(c1>k/2 || c2>k/2)
		{
			cout<<"NO"<<endl;
			continue;
		}
		// cout<<"YES"<<endl;
		while(r+1<n)
		{
			if(A[l]=='0')
				c0--;
			if(A[l]=='1')
				c1--;
			if(A[r+1]=='0')
				c0++;
			if(A[r+1]=='1')
				c1++;
			l++;
			r++;
			if(c1>k/2 || c2>k/2)
		{
			flag=0;
			break;
		}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		cout<<"YES"<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
// int digit(int n)
// {
// 	int c=0;
// 	while(n!=0)
// 	{
// 		c++;
// 		n=n/10;
// 	}
// 	return c;
// }
// bool check(vector<int> a,vector<int> b)
// {
// 	for(int i=0;i<4;i++)
// 	{
// 		int flag=1;
// 		for(int j=0;j<4;j++)
// 		{
// 			if(a[(i+j)%4]!=b[j])
// 			{
// 				flag=0;
// 				break;
// 			}
// 		}
// 		if(flag==1)
// 			return true;
// 	}
// 	return false;
// }
// bool comp(pair<int,int>>a,vector<pair<int,int>>b)
// {
// 	return(a.first<b.first);
// }
// sort(a.begin(),a.end(),greater<int>());
// priority_queue<int, vector<int>, greater<int> > Q;
// int gcd(ll a, ll b)
// {
//     if (b == 0)
//         return a;
//     return gcd(b, a % b);

// }
// ll mod=1000000007;
// ll power(ll a, ll b){
// 	ll x = 1, y = a;
// 	while (b > 0){
// 		if (b%2){
// 			x = (x*y)%mod;
// 		}
// 		y = (y*y)%mod;
// 		b /= 2;
// 	}
// 	return x%mod;
// }
// ll modular_inverse(ll n){
// 	return power(n, mod-2);
// }
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t;
	cin>>t;
	// t=1;
	for(ll f=0;f<t;f++)
	{
		ll n,k;
		cin>>n>>k;
		string A;
		cin>>A;
		ll i;
		ll l=0;
		ll r=k-1;
		ll c0=0,c1=0,c2=0;
		for(i=0;i<n;i++)
		{
			if(A[i]=='1')
				c1++;
			else if(A[i]=='0')
				c0++;
			else
				c2++;
		}
		if(c0==0 && c1==0)
		{
			cout<<"YES"<<endl;
			continue;
		}
		int flag=1;
		for(i=0;i+k<n;i++)
		{
			if(A[i]=='0')
			{
				if(A[i+k]=='1')
				{
					flag=0;
					break;
				}
				if(A[i+k]=='0')
					continue;
				A[i+k]='0';
			}
			if(A[i]=='1')
			{
				if(A[i+k]=='0')
				{
					flag=0;
					break;
				}
				if(A[i+k]=='1')
					continue;
				A[i+k]='1';
			}
			if(A[i]=='?')
			{
				if(A[i+k]=='0')
				{
					A[i]='0';
				}
				if(A[i+k]=='1')
					A[i]='1';
			}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		// for(i=0;i+k<n;i++)
		// {
		// 	if(A[i]!=A[i+k])
		// 	{
		// 		flag=0;
		// 		break;
		// 	}
		// }
		// if(flag==0)
		// {
		// 	cout<<"NO"<<endl;
		// 	continue;

		// cout<<"YES"<<endl;
		c1=0;
		c2=0;
		c0=0;
		for(i=0;i<k;i++)
		{
			if(A[i]=='1')
				c1++;
			else if(A[i]=='0')
				c0++;
			else
				c2++;
		}
		if(c1>k/2 || c0>k/2)
		{
			cout<<"NO"<<endl;
			continue;
		}
		// cout<<"YES"<<endl;
		while(r+1<n)
		{
			if(A[l]=='0')
				c0--;
			if(A[l]=='1')
				c1--;
			if(A[l]=='?')
				c2--;
			if(A[r+1]=='0')
				c0++;
			if(A[r+1]=='1')
				c1++;
			if(A[r+1]=='?')
				c2++;
			l++;
			r++;
			if(c1>k/2 || c0>k/2)
		{
			flag=0;
			break;
		}
		}
		if(flag==0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		cout<<"YES"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define fatafat  ios_base::sync_with_stdio(false); cin.tie(NULL);

#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define M 1000000007
#define F first
#define S second

#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int,int>
#define mp make_pair
#define mapi map<int,int>
#define umap unordered_map<int,int>

void solve(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;

	if(s[0]=='?' && k<n && s[k]!='?' ) s[0]=s[k];

	int one=0,zero=0;
	for(int i=0;i<k;i++){
		if(s[i]=='1') one++;
		else if(s[i]=='0') zero++;
	}

	bool flag=true;
	if(one+zero==k && one!=zero) flag=false;
	else if(one>k/2 || zero>k/2) flag=false;

	if(flag){
		one=k/2-one;
		zero=k/2-zero;
		for(int i=0;i<k;i++){
			if(s[i]=='?'){
				if(one>0) s[i]='1',one--;
				else if(zero>0) s[i]='0',zero--;
				else{
					flag=false;
					break;
				}
			}
		}
	}

	if(flag){
		one=0;zero=0;
		for(int i=0;i<k;i++){
			if(s[i]=='0') zero++;
			else if(s[i]=='1') one++;
		}
		if(one==zero && one==k/2) flag=true;
		else flag=false;
		if(flag){

			for(int i=1;i<=n-k;i++){
				if(s[i+k-1]=='?') s[i+k-1]=s[i-1];
				else if(s[i+k-1]!=s[i-1]) {
					flag=false;
					break;
				}
			}
		}
	}
	// cout<<s<<"\n";
	if(flag) cout<<"YES\n";
	else cout<<"NO\n";
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	fatafat;
	int test=1;
	cin>>test;
	while(test--) solve();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define fatafat  ios_base::sync_with_stdio(false); cin.tie(NULL);

#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define M 1000000007
#define F first
#define S second

#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int,int>
#define mp make_pair
#define mapi map<int,int>
#define umap unordered_map<int,int>

void solve(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;

	for(int i=0;i<k;i++){
		if(s[i]=='?'){
			for(int j=i+k;j<n;j+=k){
				if(s[j]!='?'){
					s[i]=s[j];
					break;
				}
			}
		}
	}

	int one=0,zero=0;
	for(int i=0;i<k;i++){
		if(s[i]=='1') one++;
		else if(s[i]=='0') zero++;
	}

	bool flag=true;
	if(one+zero==k && one!=zero) flag=false;
	else if(one>k/2 || zero>k/2) flag=false;

	if(flag){
		one=k/2-one;
		zero=k/2-zero;
		for(int i=0;i<k;i++){
			if(s[i]=='?'){
				if(one>0) s[i]='1',one--;
				else if(zero>0) s[i]='0',zero--;
				else{
					flag=false;
					break;
				}
			}
		}
	}

	if(flag){
		one=0;zero=0;
		for(int i=0;i<k;i++){
			if(s[i]=='0') zero++;
			else if(s[i]=='1') one++;
		}
		if(one==zero && one==k/2) flag=true;
		else flag=false;
		if(flag){

			for(int i=1;i<=n-k;i++){
				if(s[i+k-1]=='?') s[i+k-1]=s[i-1];
				else if(s[i+k-1]!=s[i-1]) {
					flag=false;
					break;
				}
			}
		}
	}
	// cout<<s<<"\n";
	if(flag) cout<<"YES\n";
	else cout<<"NO\n";
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	fatafat;
	int test=1;
	cin>>test;
	while(test--) solve();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define fatafat  ios_base::sync_with_stdio(false); cin.tie(NULL);

#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define M 1000000007
#define F first
#define S second

#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int,int>
#define mp make_pair
#define mapi map<int,int>
#define umap unordered_map<int,int>

void solve(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int one=0,zero=0;
	for(int i=0;i<k;i++){
		if(s[i]=='0') zero++;
		else if(s[i]=='1')one++;
	}
	// cout<<one<<" "<<zero<<" \n";
	bool flag=true;
	if(zero+one!=k){
		if(s[0]=='?'){
			if(k<n && s[k]=='0') s[0]='0',zero++;
			else if(k<n && s[k]=='1') s[1]='1',one++;
		}
		one=k/2-one;
		zero=k/2-zero;
		for(int i=0;i<k;i++){
			if(s[i]=='?'){
				if(one>0) s[i]='1',one--;
				else s[i]='0',zero--;
			}
		}
	}
	else if(one != zero) flag=false;
	one=0,zero=0;
	for(int i=0;i<k;i++){
		if(s[i]=='0') zero++;
		else one++;
	}
	// cout<<s<<"\n";
	if(one!=zero) flag=false;

	if(flag){
		for(int i=1;i<=n-k;i++){
			if(s[i+k-1]=='?') s[i+k-1]=s[i-1];
			else if(s[i+k-1]!=s[i-1]){
				flag=false;
				break;
			}
		}
	}
	// cout<<s<<"\n";
	if(flag) cout<<"YES\n";
	else cout<<"NO\n";
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	fatafat;
	int test=1;
	cin>>test;
	while(test--) solve();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define fatafat  ios_base::sync_with_stdio(false); cin.tie(NULL);

#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define M 1000000007
#define F first
#define S second

#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int,int>
#define mp make_pair
#define mapi map<int,int>
#define umap unordered_map<int,int>

void solve(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;

	if(s[0]=='?' && s[k]!='?' && k<n) s[0]=s[k];

	int one=0,zero=0;
	for(int i=0;i<k;i++){
		if(s[i]=='1') one++;
		else if(s[i]=='0') zero++;
	}

	bool flag=true;
	if(one+zero==k && one!=zero) flag=false;
	else if(one>k/2 || zero>k/2) flag=false;

	if(flag){
		one=k/2-one;
		zero=k/2-zero;
		for(int i=0;i<k;i++){
			if(s[i]=='?'){
				if(one>0) s[i]='1',one--;
				else if(zero>0) s[i]='0',zero--;
			}
		}
	}

	if(flag){
		for(int i=1;i<=n-k;i++){
			if(s[i+k-1]=='?') s[i+k-1]=s[i-1];
			else if(s[i+k-1]!=s[i-1]) {
				flag=false;
				break;
			}
		}
	}
	// cout<<s<<"\n";
	if(flag) cout<<"YES\n";
	else cout<<"NO\n";
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	fatafat;
	int test=1;
	cin>>test;
	while(test--) solve();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define fatafat  ios_base::sync_with_stdio(false); cin.tie(NULL);

#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define M 1000000007
#define F first
#define S second

#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int,int>
#define mp make_pair
#define mapi map<int,int>
#define umap unordered_map<int,int>

void solve(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;

	for(int i=0;i<k;i++){
		if(s[i]=='?'){
			for(int j=i+k;j<n;j+=k){
				if(s[j]!='?'){
					s[i]=s[j];
					break;
				}
			}
		}
	}

	int one=0,zero=0;
	for(int i=0;i<k;i++){
		if(s[i]=='1') one++;
		else if(s[i]=='0') zero++;
	}

	bool flag=true;
	if(one+zero==k && one!=zero) flag=false;
	else if(one>k/2 || zero>k/2) flag=false;

	if(flag){
		one=k/2-one;
		zero=k/2-zero;
		for(int i=0;i<k;i++){
			if(s[i]=='?'){
				if(one>0) s[i]='1',one--;
				else if(zero>0) s[i]='0',zero--;
				else{
					flag=false;
					break;
				}
			}
		}
	}

	if(flag){
		if(flag){
			for(int i=1;i<=n-k;i++){
				if(s[i+k-1]=='?') s[i+k-1]=s[i-1];
				else if(s[i+k-1]!=s[i-1]) {
					flag=false;
					break;
				}
			}
		}
	}
	// cout<<s<<"\n";
	if(flag) cout<<"YES\n";
	else cout<<"NO\n";
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	fatafat;
	int test=1;
	cin>>test;
	while(test--) solve();

	return 0;
}


#include <bits/stdc++.h>

#define pi 3.1415926535897932384626
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define vpi vector<pii>
#define vpl vector<pll>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>
#define all(v) v.begin(),v.end()
#define clr(x, n) memset(x,0,x+n)
#define trs(itr, v) for(auto itr = v.begin(); itr != v.end(); ++itr)
#define f0n(i, n) for(int i=0;i<n;++i)
#define fn0(i, n) for(int i=n;i--;)
#define fkn(i, k, n) for(int i=k;i<=n;++i)
#define fnk(i, k, n) for(int i=n;i>=k;--i)
#define deb(x) cout<<#x<<"="<<x<<endl
#define debb(x) cout<<x<<" "

using namespace std;

const int N=1e6+1;
const int M=N;
const int mod=998244353;
ll a[N], b[N], c[N];

void solve(){
    string s;
    int n, k; cin>>n>>k>>s;
    int k2=k/2;
    int zeros=0, ones=0;

    f0n(i, n){
        if(i<k)continue;
        if(s[i]=='1'){
            if(s[i-k]=='?')s[i-k]='1';
            else if(s[i-k]=='0'){
                cout<<"NO"<<endl;
                return;
            }
        }
        else if(s[i]=='0'){
            if(s[i-k]=='?')s[i-k]='0';
            else if(s[i-k]=='1'){
                cout<<"NO"<<endl;
                return;
            }
        }
    }

    fn0(i, n){
        if(i+k>=n)continue;
        if(s[i]=='1'){
            if(s[i+k]=='?')s[i+k]='1';
            else if(s[i+k]=='0'){
                cout<<"NO"<<endl;
                return;
            }
        }
        else if(s[i]=='0'){
            if(s[i+k]=='?')s[i+k]='0';
            else if(s[i+k]=='1'){
                cout<<"NO"<<endl;
                return;
            }
        }
    }

    f0n(i, n){
        if(i>=k){
            if(s[i-k]=='0')--zeros;
            else if(s[i-k]=='1')--ones;
        }

        if(s[i]=='0')++zeros;
        else if(s[i]=='1')++ones;

        if(zeros>k2 || ones>k2){
            cout<<"NO"<<endl;
            return;
        }
        if(i>=k && ((s[i]=='1' && s[i-k]=='0') || (s[i]=='0' && s[i-k]=='1'))){
            cout<<"NO"<<endl;
            return;
        }
    }

    ones=zeros=0;
    f0n(i, n){
        if(i+k<n){
            if(s[i+k]=='0')--zeros;
            else if(s[i+k]=='1')--ones;
        }

        if(s[i]=='0')++zeros;
        else if(s[i]=='1')++ones;

        if(zeros>k2 || ones>k2){
            cout<<"NO"<<endl;
            return;
        }
        if(i+k<n && ((s[i]=='1' && s[i+k]=='0') || (s[i]=='0' && s[i+k]=='1'))){
            cout<<"NO"<<endl;
            return;
        }
    }

    cout<<"YES"<<endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
#ifdef _DEBUG
    clock_t ct=clock();
    freopen("input.txt", "r", stdin);
#endif
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }

#ifdef _DEBUG
    ct=clock()-ct;
    cout<<"\ntime taken: "<<(float(ct)/CLOCKS_PER_SEC)<<endl;
#endif
}


#include <bits/stdc++.h>

#define pi 3.1415926535897932384626
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define vpi vector<pii>
#define vpl vector<pll>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>
#define all(v) v.begin(),v.end()
#define clr(x, n) memset(x,0,x+n)
#define trs(itr, v) for(auto itr = v.begin(); itr != v.end(); ++itr)
#define f0n(i, n) for(int i=0;i<n;++i)
#define fn0(i, n) for(int i=n;i--;)
#define fkn(i, k, n) for(int i=k;i<=n;++i)
#define fnk(i, k, n) for(int i=n;i>=k;--i)
#define deb(x) cout<<#x<<"="<<x<<endl
#define debb(x) cout<<x<<" "

using namespace std;

const int N=1e6+1;
const int M=N;
const int mod=998244353;
ll a[N], b[N], c[N];

void solve(){
    string s;
    int n, k; cin>>n>>k>>s;
    int k2=k/2;
    int zeros=0, ones=0;

    f0n(i, n){
        if(s[i]=='1'){
            if(i>=k){
                if(s[i-k]=='?')s[i-k]='1';
                if(s[i-k]=='0'){
                    cout<<"NO"<<endl;
                    return;
                }
            }
            if(i+k<n){
                if(s[i+k]=='?')s[i+k]='1';
                if(s[i+k]=='0'){
                    cout<<"NO"<<endl;
                    return;
                }
            }
        }
        else if(s[i]=='0'){
            if(i>=k){
                if(s[i-k]=='?')s[i-k]='0';
                if(s[i-k]=='1'){
                    cout<<"NO"<<endl;
                    return;
                }
            }
            if(i+k<n){
                if(s[i+k]=='?')s[i+k]='0';
                if(s[i+k]=='1'){
                    cout<<"NO"<<endl;
                    return;
                }
            }

        }
    }

    f0n(i, n){
        if(i>=k){
            if(s[i-k]=='0')--zeros;
            else if(s[i-k]=='1')--ones;
        }

        if(s[i]=='0')++zeros;
        else if(s[i]=='1')++ones;

        if(zeros>k2 || ones>k2){
            cout<<"NO"<<endl;
            return;
        }
    }

    cout<<"YES"<<endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
#ifdef _DEBUG
    clock_t ct=clock();
    freopen("input.txt", "r", stdin);
#endif
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }

#ifdef _DEBUG
    ct=clock()-ct;
    cout<<"\ntime taken: "<<(float(ct)/CLOCKS_PER_SEC)<<endl;
#endif
}


#include <bits/stdc++.h>

#define pi 3.1415926535897932384626
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define vpi vector<pii>
#define vpl vector<pll>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>
#define all(v) v.begin(),v.end()
#define clr(x, n) memset(x,0,x+n)
#define trs(itr, v) for(auto itr = v.begin(); itr != v.end(); ++itr)
#define f0n(i, n) for(int i=0;i<n;++i)
#define fn0(i, n) for(int i=n;i--;)
#define fkn(i, k, n) for(int i=k;i<=n;++i)
#define fnk(i, k, n) for(int i=n;i>=k;--i)
#define deb(x) cout<<#x<<"="<<x<<endl
#define debb(x) cout<<x<<" "

using namespace std;

const int N=1e6+1;
const int M=N;
const int mod=998244353;
ll a[N], b[N], c[N];

void solve(){
    string s;
    int n, k; cin>>n>>k>>s;
    int k2=k/2;
    int zeros=0, ones=0;

    f0n(i, n){
        if(i<k)continue;
        if(s[i]=='1'){
            if(s[i-k]=='?')s[i-k]='1';
            else if(s[i-k]=='0'){
                cout<<"NO"<<endl;
                return;
            }
        }
        else if(s[i]=='0'){
            if(s[i-k]=='?')s[i-k]='0';
            else if(s[i-k]=='1'){
                cout<<"NO"<<endl;
                return;
            }
        }

    }

    f0n(i, n){
        if(i>=k){
            if(s[i-k]=='0')--zeros;
            else if(s[i-k]=='1')--ones;
        }

        if(s[i]=='0')++zeros;
        else if(s[i]=='1')++ones;

        if(zeros>k2 || ones>k2){
            cout<<"NO"<<endl;
            return;
        }
        if(i>=k && ((s[i]=='1' && s[i-k]=='0') || (s[i]=='0' && s[i-k]=='1'))){
            cout<<"NO"<<endl;
            return;
        }
    }

    cout<<"YES"<<endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
#ifdef _DEBUG
    clock_t ct=clock();
    freopen("input.txt", "r", stdin);
#endif
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }

#ifdef _DEBUG
    ct=clock()-ct;
    cout<<"\ntime taken: "<<(float(ct)/CLOCKS_PER_SEC)<<endl;
#endif
}


#include <bits/stdc++.h>

#define pi 3.1415926535897932384626
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define vpi vector<pii>
#define vpl vector<pll>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>
#define all(v) v.begin(),v.end()
#define clr(x, n) memset(x,0,x+n)
#define trs(itr, v) for(auto itr = v.begin(); itr != v.end(); ++itr)
#define f0n(i, n) for(int i=0;i<n;++i)
#define fn0(i, n) for(int i=n;i--;)
#define fkn(i, k, n) for(int i=k;i<=n;++i)
#define fnk(i, k, n) for(int i=n;i>=k;--i)
#define deb(x) cout<<#x<<"="<<x<<endl
#define debb(x) cout<<x<<" "

using namespace std;

const int N=1e6+1;
const int M=N;
const int mod=998244353;
ll a[N], b[N], c[N];

void solve(){
    string s;
    int n, k; cin>>n>>k>>s;
    int k2=k/2;
    int zeros=0, ones=0;

    f0n(i, n){
        if(i<k)continue;
        if(s[i]=='1'){
            if(s[i-k]=='?')s[i-k]='1';
            else if(s[i-k]=='0'){
                cout<<"NO"<<endl;
                return;
            }
        }
        else if(s[i]=='0'){
            if(s[i-k]=='?')s[i-k]='0';
            else if(s[i-k]=='1'){
                cout<<"NO"<<endl;
                return;
            }
        }
    }

    fn0(i, n){
        if(i+k>=n)continue;
        if(s[i]=='1'){
            if(s[i+k]=='?')s[i+k]='1';
            else if(s[i+k]=='0'){
                cout<<"NO"<<endl;
                return;
            }
        }
        else if(s[i]=='0'){
            if(s[i+k]=='?')s[i+k]='0';
            else if(s[i+k]=='1'){
                cout<<"NO"<<endl;
                return;
            }
        }
    }

    f0n(i, n){
        if(i>=k){
            if(s[i-k]=='0')--zeros;
            else if(s[i-k]=='1')--ones;
        }

        if(s[i]=='0')++zeros;
        else if(s[i]=='1')++ones;

        if(zeros>k2 || ones>k2){
            cout<<"NO"<<endl;
            return;
        }
        if(i>=k && ((s[i]=='1' && s[i-k]=='0') || (s[i]=='0' && s[i-k]=='1'))){
            cout<<"NO"<<endl;
            return;
        }
    }

    f0n(i, n){
        if(i+k<n && ((s[i]=='1' && s[i+k]=='0') || (s[i]=='0' && s[i+k]=='1'))){
            cout<<"NO"<<endl;
            return;
        }
    }

    cout<<"YES"<<endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
#ifdef _DEBUG
    clock_t ct=clock();
    freopen("input.txt", "r", stdin);
#endif
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }

#ifdef _DEBUG
    ct=clock()-ct;
    cout<<"\ntime taken: "<<(float(ct)/CLOCKS_PER_SEC)<<endl;
#endif
}


#include <bits/stdc++.h>

#define pi 3.1415926535897932384626
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define vpi vector<pii>
#define vpl vector<pll>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>
#define all(v) v.begin(),v.end()
#define clr(x, n) memset(x,0,x+n)
#define trs(itr, v) for(auto itr = v.begin(); itr != v.end(); ++itr)
#define f0n(i, n) for(int i=0;i<n;++i)
#define fn0(i, n) for(int i=n;i--;)
#define fkn(i, k, n) for(int i=k;i<=n;++i)
#define fnk(i, k, n) for(int i=n;i>=k;--i)
#define deb(x) cout<<#x<<"="<<x<<endl
#define debb(x) cout<<x<<" "

using namespace std;

const int N=1e6+1;
const int M=N;
const int mod=998244353;
ll a[N], b[N], c[N];

void solve(){
    string s;
    int n, k; cin>>n>>k>>s;
    int k2=k/2;
    int zeros=0, ones=0;

    f0n(i, n){
        if(i<k)continue;
        if(s[i]=='1'){
            if(s[i-k]=='?')s[i-k]='1';
            else if(s[i-k]=='0'){
                cout<<"NO"<<endl;
                return;
            }
        }
        else if(s[i]=='0'){
            if(s[i-k]=='?')s[i-k]='0';
            else if(s[i-k]=='1'){
                cout<<"NO"<<endl;
                return;
            }
        }
    }

    fn0(i, n){
        if(i+k>=n)continue;
        if(s[i]=='1'){
            if(s[i+k]=='?')s[i+k]='1';
            else if(s[i+k]=='0'){
                cout<<"NO"<<endl;
                return;
            }
        }
        else if(s[i]=='0'){
            if(s[i+k]=='?')s[i+k]='0';
            else if(s[i+k]=='1'){
                cout<<"NO"<<endl;
                return;
            }
        }
    }

    f0n(i, n){
        if(i>=k){
            if(s[i-k]=='0')--zeros;
            else if(s[i-k]=='1')--ones;
        }

        if(s[i]=='0')++zeros;
        else if(s[i]=='1')++ones;

        if(zeros>k2 || ones>k2){
            cout<<"NO"<<endl;
            return;
        }
        if(i>=k && ((s[i]=='1' && s[i-k]=='0') || (s[i]=='0' && s[i-k]=='1'))){
            cout<<"NO"<<endl;
            return;
        }
    }

    ones=zeros=0;
    fn0(i, n){
        if(i+k<n){
            if(s[i+k]=='0')--zeros;
            else if(s[i+k]=='1')--ones;
        }

        if(s[i]=='0')++zeros;
        else if(s[i]=='1')++ones;

        if(zeros>k2 || ones>k2){
            cout<<"NO"<<endl;
            return;
        }
        if(i+k<n && ((s[i]=='1' && s[i+k]=='0') || (s[i]=='0' && s[i+k]=='1'))){
            cout<<"NO"<<endl;
            return;
        }
    }

    cout<<"YES"<<endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
#ifdef _DEBUG
    clock_t ct=clock();
    freopen("input.txt", "r", stdin);
#endif
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }

#ifdef _DEBUG
    ct=clock()-ct;
    cout<<"\ntime taken: "<<(float(ct)/CLOCKS_PER_SEC)<<endl;
#endif
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long int
#define ldb long double

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

//1.gcd(x, y);

//2.Instead of push_back() in STL emplace_back can be used

/*3.  Use of strlen() can be avoided by:
for (i=0; s[i]; i++)
{
}
//4. loop breaks when the character array ends. */

//5. Number of digits in N =floor(log10(N)) + 1;

//6. copy_n(source, 5, target);::copies 5 elements from source->target

/*7. int a[5] = {0};
char c[3] = {0};

// changes a to {10, 11, 12, 13, 14}
iota(a, a+5, 10);
iota(c, c+3, 'a'); // {'a', 'b', 'c'}*/

//8.binary_search(startaddress, endaddress, valuetofind)-> exists in c++

//9. Creates a vector of size N and values as 0.::vector<int> v(N, 0);

//TO DO LIST
//1
/*trees and graphs, such as the Kruskal and Prim algorithms, AVL trees,
tries, topological sort, traversals on all kinds of trees, and searches in graphs.*/
//dp

struct Node{
	int val;
	Node * next;
	Node(int x): val(x), next(NULL){}
};
struct TreeNode{
	int val;
	TreeNode * left;
	TreeNode* right;
	TreeNode(int x): val(x),left(NULL),right(NULL){}
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

char c(int i)
{
	return "abcdefghijklmnopqrstuvwxyz"[i%26];
}

void addEdge(vector<int> adj[], int u, int v)
{
    adj[u].push_back(v);
    adj[v].push_back(u);
}
int isPalindrome(string s)
{
    string p=s;
    reverse(s.begin(),s.end());
    if(s==p)return 1;
    return 0;
}
int isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return 0;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return 0;

    return 1;
}
int isBalanced(string s)
{
	ll z=0;
	ll o=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0')z++;
		if(s[i]=='1')o++;
	}
	if(o<=(s.size()/2)&&z<=(s.size()/2))return 1;
	return 0;
}
int main(){
    fastio;
    ll tt;tt=1;
    cin>>tt;
    while(tt--)
    {
    	ll n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		string ans="YES";
		for(int i=0;i<n-k;i++)
		{
			if(s[i]=='?')continue;
			if(s[i+k]=='?'){s[i+k]=s[i];continue;}
			if(s[i]==s[i+k])continue;
			ans="NO";
			break;
		}
		for(int i=0;i<=s.size()-k;i++)
		{
			string p=s.substr(i,k);
			if(isBalanced(p)==0)ans="NO";
		}

		cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long int
#define ldb long double

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

//1.gcd(x, y);

//2.Instead of push_back() in STL emplace_back can be used

/*3.  Use of strlen() can be avoided by:
for (i=0; s[i]; i++)
{
}
//4. loop breaks when the character array ends. */

//5. Number of digits in N =floor(log10(N)) + 1;

//6. copy_n(source, 5, target);::copies 5 elements from source->target

/*7. int a[5] = {0};
char c[3] = {0};

// changes a to {10, 11, 12, 13, 14}
iota(a, a+5, 10);
iota(c, c+3, 'a'); // {'a', 'b', 'c'}*/

//8.binary_search(startaddress, endaddress, valuetofind)-> exists in c++

//9. Creates a vector of size N and values as 0.::vector<int> v(N, 0);

//TO DO LIST
//1
/*trees and graphs, such as the Kruskal and Prim algorithms, AVL trees,
tries, topological sort, traversals on all kinds of trees, and searches in graphs.*/
//dp

struct Node{
	int val;
	Node * next;
	Node(int x): val(x), next(NULL){}
};
struct TreeNode{
	int val;
	TreeNode * left;
	TreeNode* right;
	TreeNode(int x): val(x),left(NULL),right(NULL){}
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

char c(int i)
{
	return "abcdefghijklmnopqrstuvwxyz"[i%26];
}

void addEdge(vector<int> adj[], int u, int v)
{
    adj[u].push_back(v);
    adj[v].push_back(u);
}
int isPalindrome(string s)
{
    string p=s;
    reverse(s.begin(),s.end());
    if(s==p)return 1;
    return 0;
}
int isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return 0;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return 0;

    return 1;
}
int isBalanced(string s)
{
	ll z=0;
	ll o=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0')z++;
		if(s[i]=='1')o++;
	}
	if(o<=(s.size()/2)&&z<=(s.size()/2))return 1;
	return 0;
}
int main(){
    fastio;
    ll tt;tt=1;
    cin>>tt;
    while(tt--)
    {
    	ll n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		string ans="YES";
		for(int i=0;i<n-k;i++)
		{
			if(s[i]=='?')continue;
			if(s[i+k]=='?')continue;
			if(s[i]==s[i+k])continue;
			ans="NO";
			break;
		}
		cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long int
#define ldb long double

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

//1.gcd(x, y);

//2.Instead of push_back() in STL emplace_back can be used

/*3.  Use of strlen() can be avoided by:
for (i=0; s[i]; i++)
{
}
//4. loop breaks when the character array ends. */

//5. Number of digits in N =floor(log10(N)) + 1;

//6. copy_n(source, 5, target);::copies 5 elements from source->target

/*7. int a[5] = {0};
char c[3] = {0};

// changes a to {10, 11, 12, 13, 14}
iota(a, a+5, 10);
iota(c, c+3, 'a'); // {'a', 'b', 'c'}*/

//8.binary_search(startaddress, endaddress, valuetofind)-> exists in c++

//9. Creates a vector of size N and values as 0.::vector<int> v(N, 0);

//TO DO LIST
//1
/*trees and graphs, such as the Kruskal and Prim algorithms, AVL trees,
tries, topological sort, traversals on all kinds of trees, and searches in graphs.*/
//dp

struct Node{
	int val;
	Node * next;
	Node(int x): val(x), next(NULL){}
};
struct TreeNode{
	int val;
	TreeNode * left;
	TreeNode* right;
	TreeNode(int x): val(x),left(NULL),right(NULL){}
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

char c(int i)
{
	return "abcdefghijklmnopqrstuvwxyz"[i%26];
}

void addEdge(vector<int> adj[], int u, int v)
{
    adj[u].push_back(v);
    adj[v].push_back(u);
}
int isPalindrome(string s)
{
    string p=s;
    reverse(s.begin(),s.end());
    if(s==p)return 1;
    return 0;
}
int isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return 0;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return 0;

    return 1;
}
int isBalanced(string s)
{
	ll z=0;
	ll o=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0')z++;
		if(s[i]=='1')o++;
	}
	if(o<=(s.size()/2)&&z<=(s.size()/2))return 1;
	return 0;
}
int main(){
    fastio;
    ll tt;tt=1;
    cin>>tt;
    while(tt--)
    {
    	ll n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		string ans="YES";
		for(int i=0;i<n-k;i++)
		{
			if(a[i]=='?')continue;
			if(a[i+k]=='?')continue;
			if(a[i]==a[i+k])continue;
			ans="NO";
			break;
		}
		cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long int
#define ldb long double

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

//1.gcd(x, y);

//2.Instead of push_back() in STL emplace_back can be used

/*3.  Use of strlen() can be avoided by:
for (i=0; s[i]; i++)
{
}
//4. loop breaks when the character array ends. */

//5. Number of digits in N =floor(log10(N)) + 1;

//6. copy_n(source, 5, target);::copies 5 elements from source->target

/*7. int a[5] = {0};
char c[3] = {0};

// changes a to {10, 11, 12, 13, 14}
iota(a, a+5, 10);
iota(c, c+3, 'a'); // {'a', 'b', 'c'}*/

//8.binary_search(startaddress, endaddress, valuetofind)-> exists in c++

//9. Creates a vector of size N and values as 0.::vector<int> v(N, 0);

//TO DO LIST
//1
/*trees and graphs, such as the Kruskal and Prim algorithms, AVL trees,
tries, topological sort, traversals on all kinds of trees, and searches in graphs.*/
//dp
vector<vector<int>> adj;

struct Node{
	int val;
	Node * next;
	Node(int x): val(x), next(NULL){}
};
struct TreeNode{
	int val;
	TreeNode * left;
	TreeNode* right;
	TreeNode(int x): val(x),left(NULL),right(NULL){}
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

char c(int i)
{
	return "abcdefghijklmnopqrstuvwxyz"[i%26];
}

void addEdge(int u, int v)
{
    adj[u].push_back(v);
    adj[v].push_back(u);
}
int isPalindrome(string s)
{
    string p=s;
    reverse(s.begin(),s.end());
    if(s==p)return 1;
    return 0;
}
int isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return 0;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return 0;

    return 1;
}

int main(){
    fastio;
    ll tt;tt=1;
    cin>>tt;
    while(tt--)
    {ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int z=1;
	for(int i=k;i<n;i++)
	{
		if(s[i]=='?'&&s[i-k]=='?')continue;
		if(s[i]=='?'){s[i]=s[i-k];continue;}
		if(s[i-k]=='?'){s[i-k]=s[i];continue;}
		if(s[i]!=s[i-k]){z=0;}//cout<<i<<" "<<s[i]<<" "<<s[i-k]<<endl;cout<<"cool"<<endl;
	}
	for(int i=n-1;i>=k;i--)
	{
		if(s[i]=='?'&&s[i-k]=='?')continue;
		if(s[i]=='?'){s[i]=s[i-k];continue;}
		if(s[i-k]=='?'){s[i-k]=s[i];continue;}
		if(s[i]!=s[i-k])z=0;
	}
	if(z==0){cout<<"NO"<<endl;continue;}
	int a=0;
	int b=0;
	for(int i=0;i<k;i++)
	{
		if(s[i]=='0')a++;
		if(s[i]=='1')b++;
	}
	if(a<=(k/2)&&b<=(k/2)){cout<<"YES"<<endl;}
	else cout<<"NO"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long int
#define ldb long double

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

//1.gcd(x, y);

//2.Instead of push_back() in STL emplace_back can be used

/*3.  Use of strlen() can be avoided by:
for (i=0; s[i]; i++)
{
}
//4. loop breaks when the character array ends. */

//5. Number of digits in N =floor(log10(N)) + 1;

//6. copy_n(source, 5, target);::copies 5 elements from source->target

/*7. int a[5] = {0};
char c[3] = {0};

// changes a to {10, 11, 12, 13, 14}
iota(a, a+5, 10);
iota(c, c+3, 'a'); // {'a', 'b', 'c'}*/

//8.binary_search(startaddress, endaddress, valuetofind)-> exists in c++

//9. Creates a vector of size N and values as 0.::vector<int> v(N, 0);

//TO DO LIST
//1
/*trees and graphs, such as the Kruskal and Prim algorithms, AVL trees,
tries, topological sort, traversals on all kinds of trees, and searches in graphs.*/
//dp

struct Node{
	int val;
	Node * next;
	Node(int x): val(x), next(NULL){}
};
struct TreeNode{
	int val;
	TreeNode * left;
	TreeNode* right;
	TreeNode(int x): val(x),left(NULL),right(NULL){}
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

char c(int i)
{
	return "abcdefghijklmnopqrstuvwxyz"[i%26];
}

void addEdge(vector<int> adj[], int u, int v)
{
    adj[u].push_back(v);
    adj[v].push_back(u);
}
int isPalindrome(string s)
{
    string p=s;
    reverse(s.begin(),s.end());
    if(s==p)return 1;
    return 0;
}
int isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return 0;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return 0;

    return 1;
}
int isBalanced(string s)
{
	ll z=0;
	ll o=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0')z++;
		if(s[i]=='1')o++;
	}
	if(o<=(s.size()/2)&&z<=(s.size()/2))return 1;
	return 0;
}
int main(){
    fastio;
    ll tt;tt=1;
    cin>>tt;
    while(tt--)
    {
    	ll n,k;
		cin>>n>>k;
		string s;
		cin>>s;
		string ans="YES";
		for(int i=0;i<n-k;i++)
		{
			if(s[i]=='?')continue;
			if(s[i+k]=='?'){s[i+k]=s[i];continue;}
			if(s[i]==s[i+k])continue;
			ans="NO";
			break;
		}
		cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
    #include <math.h>

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }

    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }

    void solve(){
        int n,k;
        cin>>n>>k;
        string s;
        cin>>s;
        for(int i=0;i<k;i++){
            if(s[i]=='?'){
                for(int j=i+k;j<n;j+=k){
                    if(s[j]!='?'){
                        s[i]=s[j];
                        break;
                    }
                }
            }
        }
        // cout<<"in "<<s<<"\n";
        for(int i=0;i<k;i++){
            if(s[i]!='?'){
                for(int j=i+k;j<n;j+=k){
                    if(s[j]=='?')
                        s[j]=s[i];
                    else if(s[j]!=s[i]){
                        // cout<<"hehe";
                        cout<<"NO"<<"\n";
                        return;
                    }
                }
            }
        }
        int one=0,zero=0;
        for(int i=0;i<k;i++){
            if(s[i]=='1')
                one++;
            if(s[i]=='0')
                zero++;
        }
        // cout<<"oz "<<one<<" "<<zero<<"\n";
        if(one<=(k/2) && zero<=(k/2))
            cout<<"YES"<<"\n";
        else{
            cout<<"NO"<<"\n";
        }
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long int ll;
// Declare a multimap
multimap<int, string> MM;

int main() {
	// your code goes here
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,i;
        cin>>n>>k;
        ll q=0,f=1,o=0,z=0,j;
        string s;
        cin>>s;
        for(i=0;i<n;i++)
        {
            if(s[i]=='?')
            {
                f=0;
                for(j=i+k;j<n;j=j+k)
                {
                    if(s[j]!='?')
                    {
                        s[i]=s[j];
                        break;
                    }
                }
            }
        }
        f=1;
        for(i=0;i<n;i++)
        {
            if(s[i]!='?')
            {
                for(j=i+k;j<n;j=j+k)
                {
                    if(s[j]!='?' && s[j]!=s[i])
                    {
                        f=0;
                        cout<<"NO\n";
                        break;
                    }
                    else if(s[j]=='?')
                    {
                        s[j]=s[i];
                    }
                }
            }
            if(f==0)
                break;
        }
        if(f==1)
        {
            for(i=0;i<k;i++)
            {
                if(s[i]=='1')
                    o++;
                if(s[i]=='0')
                    z++;
            }
            if(o<=k/2 && z<=k/2)
                cout<<"YES\n";
            else
                cout<<"NO\n";
        }

    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long int ll;
// Declare a multimap
multimap<int, string> MM;

int main() {
	// your code goes here
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,i;
        cin>>n>>k;
        ll q=0,f=1,o=0,z=0,j;
        string s;
        cin>>s;
        for(i=0;i<k;i++)
        {
            if(s[i]=='?')
            {
                f=0;
                for(j=i+k;j<n;j=j+k)
                {
                    if(s[j]!='?')
                    {
                        s[i]=s[j];
                        break;
                    }
                }
            }
        }
        f=1;
        for(i=0;i<k;i++)
        {
            if(s[i]!='?')
            {
                for(j=i+k;j<n;j=j+k)
                {
                    if(s[j]!='?' && s[j]!=s[i])
                    {
                        f=0;
                        cout<<"NO\n";
                        break;
                    }
                    else if(s[j]=='?')
                    {
                        s[j]=s[i];
                    }
                }
            }
            if(f==0)
                break;
        }
        if(f==1)
        {
            for(i=0;i<k;i++)
            {
                if(s[i]=='1')
                    o++;
                if(s[i]=='0')
                    z++;
            }
            if(o<=k/2 && z<=k/2)
                cout<<"YES\n";
            else
                cout<<"NO\n";
        }

    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long int ll;
// Declare a multimap
multimap<int, string> MM;

int main() {
	// your code goes here
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,i;
        cin>>n>>k;
        ll q=0,f=1,o=0,z=0,j;
        string s;
        cin>>s;
        for(i=0;i<n;i++)
        {
            if(s[i]=='?')
            {
                f=0;
                for(j=i+k;j<n;j=j+k)
                {
                    if(s[j]!='?')
                    {
                        s[i]=s[j];
                        break;
                    }
                }
            }
        }
        f=1;
        for(i=0;i<n;i++)
        {
            if(s[i]!='?')
            {
                for(j=i+k;j<n;j=j+k)
                {
                    if(s[j]!='?' && s[j]!=s[i])
                    {
                        f=0;
                        cout<<"NO\n";
                        break;
                    }
                    else if(s[j]=='?')
                    {
                        s[j]=s[i];
                    }
                }
            }
            if(f==0)
                break;
        }
        if(f==1)
        {
            for(i=0;i<k;i++)
            {
                if(s[i]=='1')
                    o++;
                if(s[i]=='0')
                    z++;
            }
            if(o<=k/2 && z<=k/2)
                cout<<"YES\n";
            else
                cout<<"NO\n";
        }

    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long int ll;
// Declare a multimap
multimap<int, string> MM;

int main() {
	// your code goes here
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,i;
        cin>>n>>k;
        ll q=0,f=1,o=0,z=0,j;
        string s;
        cin>>s;
        for(i=0;i<n;i++)
        {
            if(s[i]=='?')
            {
                f=0;
                for(j=i+k;j<n;j=j+k)
                {
                    if(s[j]!='?')
                    {
                        s[i]=s[j];
                        break;
                    }
                }
            }
        }
        f=1;
        for(i=0;i<n;i++)
        {
            if(s[i]!='?' && i+k<n && s[i+k]!='?' && s[i]!=s[i+k])
            {
                f=0;
                cout<<"NO\n";
                break;
            }
        }
        if(f==1)
        {
            for(i=0;i<k;i++)
            {
                if(s[i]=='1')
                    o++;
                if(s[i]=='0')
                    z++;
            }
            if(o<=k/2 && z<=k/2)
                cout<<"YES\n";
            else
                cout<<"NO\n";
        }

    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long int ll;
// Declare a multimap
multimap<int, string> MM;

int main() {
	// your code goes here
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,i;
        cin>>n>>k;
        ll q=0,f=1,o=0,z=0,j;
        string s;
        cin>>s;
        for(i=0;i<n;i++)
        {
            if(s[i]=='?')
            {
                f=0;
                for(j=i+k;j<n;j=j+k)
                {
                    if(s[j]!='?')
                    {
                        s[i]=s[j];
                        f=1;
                    }
                    else if(s[j]=='?' && f==1)
                    {
                        s[j]=s[i];
                    }
                }
            }
        }
        f=1;
        for(i=0;i<n;i++)
        {
            if(s[i]!='?' && i+k<n && s[i+k]!='?' && s[i]!=s[i+k])
            {
                f=0;
                cout<<"NO\n";
                break;
            }
        }
        if(f==1)
        {
            for(i=0;i<k;i++)
            {
                if(s[i]=='1')
                    o++;
                if(s[i]=='0')
                    z++;
            }
            if(o<=k/2 && z<=k/2)
                cout<<"YES\n";
            else
                cout<<"NO\n";
        }

    }

	return 0;
}


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
string s;
int d1,d2;
int dd[maxn];
int cnt1,cnt2,cnt3;
int f;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> t;
	while ( t-- )
	{
		f = 0; cnt1= cnt2 = cnt3 = 0;
		cin >> n >> k;
		cin >> s;
		rep(i,0,n-1) dd[i] = -1;
		rep(i,0,n-1)
		{
			if ( dd[i%k] > -1 && (s[i]- '0') + 10 != dd[i%k] && s[i] != '?')
			{
				f = 1;
				break;
			}
			else if ( dd[i] == -1 && s[i] != '?' ) dd[i%k] =  (s[i] - '0')  + 10;
		}
		for( i =n-1;i >=0; i--)
		{
			if ( dd[i%k] > -1 && (s[i]- '0') + 10 != dd[i%k] && s[i] != '?')
			{
				f = 1;
				break;
			}
			else if ( dd[i] == -1 && s[i] != '?' ) dd[i%k] =  (s[i] - '0')  + 10;
		}
		if ( f == 1 ) cout << N << endl;
		else if ( f == 0 )
		{
			rep(i,0,k-1)
			{

				if ( s[i] == '?')
				{
					if ( dd[i%k] == 10 ) s[i] = '0';
					else if ( dd[i%k] == 11 ) s[i] = '1';
				}
			}
			rep(i,0,k-1)
			{
				if ( s[i] == '0') cnt2++;
				else if ( s[i] == '1') cnt3++;
				else if ( s[i] == '?') cnt1++;
			}
			if ( cnt2 == cnt3 ) cout << Y << endl;
			else if ( cnt2 != cnt3 && cnt1 == 0 ) cout << N << endl;
			else if ( cnt2 != cnt3 && cnt2 + cnt1 == cnt3 || cnt3 + cnt1 == cnt2 ) cout << Y << endl;
			else
			{
				if ( min(cnt2,cnt3) == 0 && (cnt2 == k/2 || cnt3 == k/2 )) cout << Y << endl;
				else cout << N << endl;
			}
			//cout << s << endl;
		}

	}
}


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
string s;
int d1,d2;
int dd[maxn];
int cnt1,cnt2,cnt3;
int f;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> t;
	while ( t-- )
	{
		f = 0; cnt1= cnt2 = cnt3 = 0;
		cin >> n >> k;
		cin >> s;
		rep(i,0,n-1) dd[i] = -1;
		rep(i,0,n-1)
		{
			if ( dd[i%k] > -1 && (s[i]- '0') + 10 != dd[i%k] && s[i] != '?')
			{
				f = 1;
				break;
			}
			else if ( dd[i] == -1 && s[i] != '?' ) dd[i%k] =  (s[i] - '0')  + 10;
		}
		if ( f == 1 ) cout << N << endl;
		else if ( f == 0 )
		{
			rep(i,0,k-1)
			{

				if ( s[i] == '?')
				{
					if ( dd[i%k] == 10 ) s[i] = '0';
					else if ( dd[i%k] == 11 ) s[i] = '1';
				}
			}
			//rep(i,0,k-1) cout << dd[i] << " "; cout << endl;
			rep(i,0,k-1)
			{
				if ( s[i] == '0') cnt2++;
				else if ( s[i] == '1') cnt3++;
				else if ( s[i] == '?') cnt1++;
			}
			if ( cnt2 == cnt3 ) cout << Y << endl;
			else if ( cnt2 != cnt3 && cnt1 == 0 ) cout << N << endl;
			else if ( cnt2 != cnt3 && cnt2 + cnt1 == cnt3 || cnt3 + cnt1 == cnt2 ) cout << Y << endl;
			else
			{
				if ( min(cnt2,cnt3) == 0 && (cnt2 == k/2 || cnt3 == k/2 )) cout << Y << endl;
				else cout << N << endl;
			}
			//cout << s << endl;
		}

	}
}


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
string s;
int d1,d2;
int dd[maxn];
int cnt1,cnt2,cnt3;
int f;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> t;
	while ( t-- )
	{
		f = 0; cnt1= cnt2 = cnt3 = 0;
		cin >> n >> k;
		cin >> s;
		rep(i,0,n-1) dd[i] = -1;
		rep(i,0,n-1)
		{
			if ( dd[i%k] > -1 && (s[i]- '0') + 10 != dd[i%k] && s[i] != '?')
			{
				f = 1;
				break;
			}
			else if ( dd[i] == -1 && s[i] != '?' ) dd[i%k] =  (s[i] - '0')  + 10;
		}
		if ( f == 1 ) cout << N << endl;
		else if ( f == 0 )
		{
			rep(i,0,k-1)
			{

				if ( s[i] == '?')
				{
					if ( dd[i%k] == 10 ) s[i] = '0';
					else if ( dd[i%k] == 11 ) s[i] = '1';
				}
			}
			//rep(i,0,k-1) cout << dd[i] << " "; cout << endl;
			rep(i,0,k-1)
			{
				if ( s[i] == '0') cnt2++;
				else if ( s[i] == '1') cnt3++;
				else if ( s[i] == '?') cnt1++;
			}
			if ( cnt2 == cnt3 ) cout << Y << endl;
			else if ( cnt2 != cnt3 && cnt1 == 0 ) cout << N << endl;
			else if ( cnt2 != cnt3 && cnt2 + cnt1 == cnt3 || cnt3 + cnt1 == cnt2 ) cout << Y << endl;
			else
			{
				if ( min(cnt2,cnt3) == 0 && cnt2 == k/2 ) cout << Y << endl;
				else cout << N << endl;
			}
			//cout << s << endl;
		}

	}
}


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 4e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
string s;
int d1,d2;
int dd[maxn];
int cnt1,cnt2,cnt3;
int f;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> t;
	while ( t-- )
	{
		f = 0; cnt1= 0; cnt2 = 0; cnt3 = 0;
		cin >> n >> k;
		cin >> s;
		rep(i,0,n-1) dd[i] = -1;
		rep(i,0,n-1)
		{
			if ( dd[i%k] > -1 && (s[i]- '0') + 10 != dd[i%k] && s[i] != '?')
			{
				f = 1;
				break;
			}
			else if ( dd[i] == -1 && s[i] != '?' ) dd[i%k] =  (s[i] - '0')  + 10;
		}
		if ( f == 1 ) cout << N << endl;
		else if ( f == 0 )
		{
			rep(i,0,k-1)
			{

				if ( s[i] == '?')
				{
					if ( dd[i%k] == 10 ) s[i] = '0';
					else if ( dd[i%k] == 11 ) s[i] = '1';
				}
			}
			rep(i,0,k-1)
			{
				if ( s[i] == '0') cnt2++;
				else if ( s[i] == '1') cnt3++;
				else if ( s[i] == '?') cnt1++;
			}
		//	cout <<s  << endl;
			if ( cnt2 > k/2 || cnt3 > k/2 ) cout << N << endl;
			else if ( cnt2 == k/2 &&  cnt3 == k/2 ) cout << Y << endl;
			else if ( cnt2 == cnt3 && cnt1 > 0 ) cout << Y << endl;
			else if ( cnt2 != cnt3 && cnt1 == 0 ) cout << N << endl;
			else if ( cnt2 != cnt3 && cnt1 > 0 && cnt2 <= k/2 && cnt3 <= k/2 ) cout << Y << endl;
			else
			{
				if ( min(cnt2,cnt3) == 0 && (cnt2 == k/2 || cnt3 == k/2 )) cout << Y << endl;
				else if ( cnt2 == cnt3 == 0 ) cout << Y << endl;
				else cout << N << endl;
			}
			//cout << s << endl;
		}

	}
}


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
string s;
int d1,d2;
int dd[maxn];
int cnt1,cnt2,cnt3;
int f;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> t;
	while ( t-- )
	{
		f = 0; cnt1= cnt2 = cnt3 = 0;
		cin >> n >> k;
		cin >> s;
		rep(i,0,n-1) dd[i] = -1;
		rep(i,0,n-1)
		{
			if ( dd[i%k] > -1 && (s[i]- '0') + 10 != dd[i%k] && s[i] != '?')
			{
				f = 1;
				break;
			}
			else if ( dd[i] == -1 && s[i] != '?' ) dd[i%k] =  (s[i] - '0')  + 10;
		}
		if ( f == 1 ) cout << N << endl;
		else if ( f == 0 )
		{
			rep(i,0,k-1)
			{

				if ( s[i] == '?')
				{
					if ( dd[i%k] == 10 ) s[i] = '0';
					else if ( dd[i%k] == 11 ) s[i] = '1';
				}
			}
			rep(i,0,k-1)
			{
				if ( s[i] == '0') cnt2++;
				else if ( s[i] == '1') cnt3++;
				else if ( s[i] == '?') cnt1++;
			}
			if ( cnt2 == cnt3 == k/2 ) cout << Y << endl;
			else if ( cnt2 != cnt3 && cnt1 == 0 ) cout << N << endl;
			else if ( cnt2 != cnt3 && cnt1 > 0 ) cout << Y << endl;
			else
			{
				if ( min(cnt2,cnt3) == 0 && (cnt2 == k/2 || cnt3 == k/2 )) cout << Y << endl;
				else cout << N << endl;
			}
			//cout << s << endl;
		}

	}
}


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
string s;
int d1,d2;
int dd[maxn];
int cnt1,cnt2,cnt3;
int f;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> t;
	while ( t-- )
	{
		f = 0; cnt1= 0; cnt2 = 0; cnt3 = 0;
		cin >> n >> k;
		cin >> s;
		rep(i,0,n-1) dd[i] = -1;
		rep(i,0,n-1)
		{
			if ( dd[i%k] > -1 && (s[i]- '0') + 10 != dd[i%k] && s[i] != '?')
			{
				f = 1;
				break;
			}
			else if ( dd[i] == -1 && s[i] != '?' ) dd[i%k] =  (s[i] - '0')  + 10;
		}
		if ( f == 1 ) cout << N << endl;
		else if ( f == 0 )
		{
			rep(i,0,k-1)
			{

				if ( s[i] == '?')
				{
					if ( dd[i%k] == 10 ) s[i] = '0';
					else if ( dd[i%k] == 11 ) s[i] = '1';
				}
			}
			rep(i,0,k-1)
			{
				if ( s[i] == '0') cnt2++;
				else if ( s[i] == '1') cnt3++;
				else if ( s[i] == '?') cnt1++;
			}
		//	cout <<s  << endl;
			if ( cnt2 > k/2 || cnt3 > k/2 ) cout << N << endl;
			else if ( cnt2 == k/2 &&  cnt3 == k/2 ) cout << Y << endl;
			else if ( cnt2 == cnt3 && cnt1 > 0 ) cout << Y << endl;
			else if ( cnt2 != cnt3 && cnt1 == 0 ) cout << N << endl;
			else if ( cnt2 != cnt3 && cnt1 > 0 && cnt2 <= k/2 && cnt3 <= k/2 ) cout << Y << endl;
			else
			{
				if ( min(cnt2,cnt3) == 0 && (cnt2 == k/2 || cnt3 == k/2 )) cout << Y << endl;
				else if ( cnt2 == cnt3 == 0 ) cout << Y << endl;
				else cout << N << endl;
			}
			//cout << s << endl;
		}

	}
}


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
string s;
int d1,d2;
int dd[maxn];
int cnt1,cnt2,cnt3;
int f;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> t;
	while ( t-- )
	{
		f = 0; cnt1= 0; cnt2 = 0; cnt3 = 0;
		cin >> n >> k;
		cin >> s;
		rep(i,0,n-1) dd[i] = -1;
		rep(i,0,n-1)
		{
			if ( dd[i%k] > -1 && (s[i]- '0') + 10 != dd[i%k] && s[i] != '?')
			{
				f = 1;
				break;
			}
			else if ( dd[i] == -1 && s[i] != '?' ) dd[i%k] =  (s[i] - '0')  + 10;
		}
		if ( f == 1 ) cout << N << endl;
		else if ( f == 0 )
		{
			rep(i,0,k-1)
			{

				if ( s[i] == '?')
				{
					if ( dd[i%k] == 10 ) s[i] = '0';
					else if ( dd[i%k] == 11 ) s[i] = '1';
				}
			}
			rep(i,0,k-1)
			{
				if ( s[i] == '0') cnt2++;
				else if ( s[i] == '1') cnt3++;
				else if ( s[i] == '?') cnt1++;
			}
			//cout << cnt2 << " " << cnt3 << endl;
			if ( cnt2 == k/2 &&  cnt3 == k/2 ) cout << Y << endl;
			else if ( cnt2 != cnt3 && cnt1 == 0 ) cout << N << endl;
			else if ( cnt2 != cnt3 && cnt1 > 0 ) cout << Y << endl;
			else
			{
				if ( min(cnt2,cnt3) == 0 && (cnt2 == k/2 || cnt3 == k/2 )) cout << Y << endl;
				else cout << N << endl;
			}
			//cout << s << endl;
		}

	}
}


#include <iostream>//(ke2YI0gong2YU0)
#include <cstdio>//18446744073709551616
#include <cmath>// 18000000000000000000
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <stdlib.h>
#define N 300005
#define mp make_pair
#define dd double
#define int long long

using namespace std;

int T, n0[N], n1[N], res[N];
int n, k;
char c[N];

signed main(void) {
	cin >> T;
	while(T--) {
		cin >> n >> k;
		cin >> c;
		int flag = 0;
		for(int i=0; i<n; i++) {
			if(c[i] != c[i % k]) {
				if(c[i] != '?' && c[i % k] == '?') c[i % k] = c[i];
				else if(c[i] == '?') c[i] = c[i % k];
				else flag = 1;
			}
		}
		int n0 = 0, n1 = 0;
		for(int i=0; i<k; i++) {
			if(c[i] == '0') n0++;
			if(c[i] == '1') n1++;
		}
		if(n0 > k/2 || n1 > k/2) flag = 1;
		if(flag) cout << "NO" << '\n';
		else cout << "YES" << '\n';
	}
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll()

int main(){

    fast;
    int T;
    T=1;
    cin>>T;
    while(T--){
    	int n,k,i,j;
    	cin>>n>>k;
    	string s;
    	cin>>s;
    	int p1[n+1]={0};
    	int p0[n+1]={0};
    	for(i=0;i<n;i++)
    	{
    		if(s[i]=='1')
    		{
    			p1[i+1]=p1[i]+1;
			}
			else
			{
				p1[i+1]=p1[i];
			}
			if(s[i]=='0')
			{
				p0[i+1]=p0[i]+1;
			}
			else
			{
				p0[i+1]=p0[i];
			}
		}
		int x1=0,y1=0;

		vector<string>v;
		for(i=0;i<k;i++)
		{
			string s1;
			for(j=i;j<n;j=j+k)
			{
				s1.pb(s[j]);
			}
			v.pb(s1);

		}
		int x=0;
		int y=0;
		int z=0;
		int f=0;
		for(i=0;i<k;i++)
		{
			int x1=0;
			int y1=0;
			for(j=0;j<v[i].length();j++)
			{
				if(v[i][j]=='1')
				x1=1;
				if(v[i][j]=='0')
				y1=1;
			}
			if(x1&&y1)
			{
				f=1;
				break;
			}
			if(x1)
			x++;
			if(y1)
			y++;
			if(!x1&&!y1)
			z++;

		}
		if(x>k/2||y>k/2)
		{
			f=1;

		}
		if(z!=k/2-x+k/2-y)
		{
			f=1;
		}
		if(f)
		{
			cout<<"NO\n";
		}
		else
		{
			cout<<"YES\n";
		}

    }

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll()

int main(){

    fast;
    int T;
    T=1;
    cin>>T;
    while(T--){
    	int n,k,i,j;
    	cin>>n>>k;
    	string s;
    	cin>>s;
    	int p1[n+1]={0};
    	int p0[n+1]={0};
    	for(i=0;i<n;i++)
    	{
    		if(s[i]=='1')
    		{
    			p1[i+1]=p1[i]+1;
			}
			else
			{
				p1[i+1]=p1[i];
			}
			if(s[i]=='0')
			{
				p0[i+1]=p0[i]+1;
			}
			else
			{
				p0[i+1]=p0[i];
			}
		}
		int x1=0,y1=0;
		int f=0;
		for(i=1;i+k-1<=n;i++)
		{
			//cout<<x1<<" "<<y1<<"\n";
			int x=p1[i+k-1]-p1[i-1];
			int y=p0[i+k-1]-p0[i-1];
			if(x>k/2||y>k/2)
			{
				f=1;
				break;
			}
			if(i==1)
			{
				x1=k/2-x;
				y1=k/2-y;
			}
			else
			{

				if(s[i-2]=='?')
				{
					if(s[i+k-2]=='?')
					{
						continue;
					}
					else
					{
						if(s[i+k-2]=='1'&&x1>0)
						{
							continue;
						}
						else
						{
							if(s[i+k-2]=='0'&&y1>0)
							{
								continue;
							}
							else
							{
								f=1;
								break;
							}
						}

					}
				}
				else
				{
					if(s[i+k-2]=='?')
					{
						if(s[i-2]=='1'&&k/2-x>0)
						{
							continue;
						}
						else
						{
							if(s[i-2]=='0'&&k/2-y>0)
							{
								continue;
							}
							else
							{
								f=1;
								break;
							}
						}
					}
					else
					{
						if(s[i-2]!=s[i+k-2])
						{
							f=1;
							break;
						}
					}
				}
				x1=k/2-x;
				y1=k/2-y;

			}
		}
		if(f)
		{
			cout<<"NO\n";
		}
		else
		{
			cout<<"YES\n";
		}

    }

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll()

int main(){

    fast;
    int T;
    T=1;
    cin>>T;
    while(T--){
    	int n,k,i,j;
    	cin>>n>>k;
    	string s;
    	cin>>s;
    	int p1[n+1]={0};
    	int p0[n+1]={0};
    	for(i=0;i<n;i++)
    	{
    		if(s[i]=='1')
    		{
    			p1[i+1]=p1[i]+1;
			}
			else
			{
				p1[i+1]=p1[i];
			}
			if(s[i]=='0')
			{
				p0[i+1]=p0[i]+1;
			}
			else
			{
				p0[i+1]=p0[i];
			}
		}
		int x1=0,y1=0;
		int f=0;
		for(i=1;i+k-1<=n;i++)
		{
			//cout<<x1<<" "<<y1<<"\n";
			int x=p1[i+k-1]-p1[i-1];
			int y=p0[i+k-1]-p0[i-1];
			if(x>k/2||y>k/2)
			{
				f=1;
				break;
			}
			if(i==1)
			{
				x1=k/2-x;
				y1=k/2-y;
			}
			else
			{

				if(s[i-2]=='?')
				{
					if(s[i+k-2]=='?')
					{
						continue;
					}
					else
					{
						if(s[i+k-2]=='1'&&x1>0)
						{
							continue;
						}
						else
						{
							if(s[i+k-2]=='0'&&y1>0)
							{
								continue;
							}
							else
							{
								f=1;
								break;
							}
						}

					}
				}
				else
				{
					if(s[i+k-2]=='?')
					{
						if(s[i-2]=='1'&&k/2-x>0&&y1==k/2-y)
						{
							continue;
						}
						else
						{
							if(s[i-2]=='0'&&k/2-y>0&&x1==k/2-x)
							{
								continue;
							}
							else
							{
								f=1;
								break;
							}
						}
					}
					else
					{
						if(s[i-2]!=s[i+k-2])
						{
							f=1;
							break;
						}
					}
				}
				x1=k/2-x;
				y1=k/2-y;

			}
		}
		if(f)
		{
			cout<<"NO\n";
		}
		else
		{
			cout<<"YES\n";
		}

    }

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll()

int main(){

    fast;
    int T;
    T=1;
    cin>>T;
    while(T--){
    	int n,k,i,j;
    	cin>>n>>k;
    	string s;
    	cin>>s;
    	int p1[n+1]={0};
    	int p0[n+1]={0};
    	for(i=0;i<=n;i++)
    	{
    		if(s[i]=='1')
    		{
    			p1[i+1]=p1[i]+1;
			}
			else
			{
				p1[i+1]=p1[i];
			}
			if(s[i]=='0')
			{
				p0[i+1]=p0[i]+1;
			}
			else
			{
				p0[i+1]=p0[i];
			}
		}
		int x1=0,y1=0;
		int f=0;
		for(i=1;i+k-1<=n;i++)
		{
			//cout<<x1<<" "<<y1<<"\n";
			int x=p1[i+k-1]-p1[i-1];
			int y=p0[i+k-1]-p0[i-1];
			if(x>k/2||y>k/2)
			{
				f=1;
				break;
			}
			if(i==1)
			{
				x1=k/2-x;
				y1=k/2-y;
			}
			else
			{
				int f1=abs(k/2-x-x1);
				int f2=abs(k/2-y-y1);
				if(s[i-2]=='?')
				{
					if(s[i+k-2]=='?')
					{
						continue;
					}
					else
					{
						if(s[i+k-2]=='1'&&x1>0)
						{
							continue;
						}
						if(s[i+k-2]=='0'&&y1>0)
						{
							continue;
						}

							f=1;
							break;

					}
				}
				else
				{
					if(s[i+k-2]=='?')
					{
						if(s[i-2]=='1'&&k/2-x>0)
						{
							continue;
						}
						if(s[i-2]=='0'&&k/2-y>0)
						{
							continue;
						}
						f=1;
						break;
					}
					else
					{
						if(s[i-2]!=s[i+k-2])
						{
							f=1;
							break;
						}
					}
				}
				x1=k/2-x;
				y1=k/2-y;

			}
		}
		if(f)
		{
			cout<<"NO\n";
		}
		else
		{
			cout<<"YES\n";
		}

    }

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll()

int main(){

    fast;
    int T;
    T=1;
    cin>>T;
    while(T--){
    	int n,k,i,j;
    	cin>>n>>k;
    	string s;
    	cin>>s;
    	int p1[n+1]={0};
    	int p0[n+1]={0};
    	for(i=0;i<n;i++)
    	{
    		if(s[i]=='1')
    		{
    			p1[i+1]=p1[i]+1;
			}
			else
			{
				p1[i+1]=p1[i];
			}
			if(s[i]=='0')
			{
				p0[i+1]=p0[i]+1;
			}
			else
			{
				p0[i+1]=p0[i];
			}
		}
		int x1=0,y1=0;
		int f=0;
		for(i=1;i+k-1<=n;i++)
		{
			//cout<<x1<<" "<<y1<<"\n";
			int x=p1[i+k-1]-p1[i-1];
			int y=p0[i+k-1]-p0[i-1];
			if(x>k/2||y>k/2)
			{
				f=1;
				break;
			}
			if(i==1)
			{
				x1=k/2-x;
				y1=k/2-y;
			}
			else
			{

				if(s[i-2]=='?')
				{
					if(s[i+k-2]=='?')
					{
							x1=k/2-x;
				y1=k/2-y;
						continue;
					}
					else
					{
						if(s[i+k-2]=='1'&&x1>0)
						{
								x1=k/2-x;
				y1=k/2-y;
							continue;
						}
						else
						{
							if(s[i+k-2]=='0'&&y1>0)
							{
									x1=k/2-x;
				y1=k/2-y;
								continue;
							}
							else
							{
								f=1;
								break;
							}
						}

					}
				}
				else
				{
					if(s[i+k-2]=='?')
					{
						if(s[i-2]=='1'&&k/2-x>0&&y1==k/2-y)
						{
								x1=k/2-x;
				y1=k/2-y;
							continue;
						}
						else
						{
							if(s[i-2]=='0'&&k/2-y>0&&x1==k/2-x)
							{
									x1=k/2-x;
				y1=k/2-y;
								continue;
							}
							else
							{
								f=1;
								break;
							}
						}
					}
					else
					{
						if(s[i-2]!=s[i+k-2])
						{
							f=1;
							break;
						}
					}
				}

			}
		}
		if(f)
		{
			cout<<"NO\n";
		}
		else
		{
			cout<<"YES\n";
		}

    }

}