#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))

using namespace std;

const int inf = 1e9+7;
const int N = 1e5 + 50;

bool good[26];
char str[N];
char p[N];
int len;

int pos;

void getStarPos(){
    int i;
    for(i=0;str[i];++i){
        if(str[i]=='*'){
            pos=i;
            return;
        }
    }
    str[i]='*';
    pos=i;
    str[i+1]=0;
}

bool allBad(char*s,int st,int ed){
    while(st<=ed){
        if(good[s[st]-'a']){
            return false;
        }
        ++st;
    }
    return true;
}

bool checkPre(int ed){
    for(int i=0;i<=ed;++i){
        if(str[i]=='?'&&good[p[i]-'a']){
            continue;
        }
        if(str[i]!=p[i]){
            return false;
        }
    }
    return true;
}

bool checkSuffix(int stStr,int stP){
    for(int k=0;str[stStr+k];++k){
        int i=stStr+k;
        int j=stP+k;
        if(str[i]=='?'&&good[p[j]-'a']){
            continue;
        }
        if(str[i]!=p[j]){
            return false;
        }
    }
    return true;
}

bool query(){
    int lenP=strlen(p);
    return allBad(p,pos,lenP-len+pos)&&checkPre(pos-1)&&checkSuffix(pos+1,lenP-(len-pos)+1);
}

int main(){
    //freopen("/home/lu/code/r.txt","r",stdin);
    //freopen("/home/lu/code/w.txt","w",stdout);
    while(~scanf("%s",str)){
        MEM(good,0);
        for(int i=0;str[i];++i){
            good[str[i]-'a']=1;
        }
        scanf("%s",str);
        getStarPos();
        len=strlen(str);
        int q;
        scanf("%d",&q);
        while(q--){
            scanf("%s",p);
            puts(query()?"YES":"NO");
        }
    }
    return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))

using namespace std;

const int inf = 1e9+7;
const int N = 1e5 + 50;

bool good[26];
char str[N];
char p[N];
int len;
int vis[N];
bool star;

bool allBad(){
    for(int i=0;p[i];++i){
        if((!vis[i])&&good[p[i]-'a']){
            return false;
        }
    }
    return true;
}

bool checkPre(){
    for(int i=0;str[i]&&str[i]!='*';++i){
        vis[i]++;
        if(str[i]=='?'&&good[p[i]-'a']){
            continue;
        }
        if(str[i]!=p[i]){
            return false;
        }
    }
    return true;
}

bool checkSuffix(int pLen){
    int i=len-1;
    int j=pLen-1;
    for(;i>=0&&j>=0&&str[i]!='*';--i,--j){
        vis[j]++;
        if(str[i]=='?'&&good[p[j]-'a']){
            continue;
        }
        if(str[i]!=p[j]){
            return false;
        }
    }
    return true;
}

void getStar(){
    star=0;
    for(int i=0;str[i];++i){
        if(str[i]=='*'){
            star=1;
            return;
        }
    }
}

bool query(){
    int lenP=strlen(p);
    fill(vis,vis+lenP,0);
    if(lenP<len-1){
        return false;
    }
    if(star){
        return (checkPre()&&checkSuffix(lenP)&&allBad());
    }
    else{
        return lenP==len&&checkPre();
    }
}

int main(){
    //freopen("/home/lu/code/r.txt","r",stdin);
    //freopen("/home/lu/code/w.txt","w",stdout);
    while(~scanf("%s",str)){
        MEM(good,0);
        for(int i=0;str[i];++i){
            good[str[i]-'a']=1;
        }
        scanf("%s",str);
        len=strlen(str);
        getStar();
        int q;
        scanf("%d",&q);
        while(q--){
            scanf("%s",p);
            puts(query()?"YES":"NO");
        }
    }
    return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))

using namespace std;

const int inf = 1e9+7;
const int N = 1e5 + 50;

bool good[26];
char str[N];
char p[N];
int len;

bool vis[N];

bool allBad(){
    for(int i=0;p[i];++i){
        if((!vis[i])&&good[p[i]-'a']){
            return false;
        }
    }
    return true;
}

bool checkPre(){
    for(int i=0;str[i]&&str[i]!='*';++i){
        vis[i]=1;
        if(str[i]=='?'&&good[p[i]-'a']){
            continue;
        }
        if(str[i]!=p[i]){
            return false;
        }
    }
    return true;
}

bool checkSuffix(int pLen){
    for(int k=0;len-k-1>=0&&str[len-k-1]!='*';++k){
        int i=len-k-1;
        int j=pLen-k-1;
        if(i<0||j<0){
            break;
        }
        vis[j]=1;
        if(str[i]=='?'&&good[p[j]-'a']){
            continue;
        }
        if(str[i]!=p[j]){
            return false;
        }
    }
    return true;
}

bool query(){
    int lenP=strlen(p);
    fill(vis,vis+lenP,0);
    if(lenP<len-1||lenP>len){
        return false;
    }
    return (checkPre()&&checkSuffix(lenP)&&allBad());
}

int main(){
    //freopen("/home/lu/code/r.txt","r",stdin);
    //freopen("/home/lu/code/w.txt","w",stdout);
    while(~scanf("%s",str)){
        MEM(good,0);
        for(int i=0;str[i];++i){
            good[str[i]-'a']=1;
        }
        scanf("%s",str);
        len=strlen(str);
        int q;
        scanf("%d",&q);
        while(q--){
            scanf("%s",p);
            puts(query()?"YES":"NO");
        }
    }
    return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))

using namespace std;

const int inf = 1e9+7;
const int N = 1e5 + 50;

bool good[26];
char str[N];
char p[N];
int len;

int pos;

void getStarPos(){
    int i;
    for(i=0;str[i];++i){
        if(str[i]=='*'){
            pos=i;
            return;
        }
    }
    str[i]='*';
    pos=i;
    str[i+1]=0;
}

bool allBad(char*s,int st,int ed){
    while(st<=ed){
        if(good[s[st]-'a']){
            return false;
        }
        ++st;
    }
    return true;
}

bool checkPre(int ed){
    for(int i=0;i<=ed;++i){
        if(str[i]=='?'&&good[p[i]-'a']){
            continue;
        }
        if(str[i]!=p[i]){
            return false;
        }
    }
    return true;
}

bool checkSuffix(int sufLen,int pLen){
    for(int k=0;k<sufLen;++k){
        int i=len-k-1;
        int j=pLen-k-1;
        if(i<0||j<0||str[i]!=p[j]){
            return false;
        }
    }
    return true;
}

bool query(){
    int lenP=strlen(p);
    if(lenP<len-1){
        return false;
    }
    return allBad(p,pos,lenP-len+pos)&&checkPre(pos-1)&&checkSuffix(len-1-pos,lenP);
}

int main(){
    //freopen("/home/lu/code/r.txt","r",stdin);
    //freopen("/home/lu/code/w.txt","w",stdout);
    while(~scanf("%s",str)){
        MEM(good,0);
        for(int i=0;str[i];++i){
            good[str[i]-'a']=1;
        }
        scanf("%s",str);
        getStarPos();
        len=strlen(str);
        int q;
        scanf("%d",&q);
        while(q--){
            scanf("%s",p);
            puts(query()?"YES":"NO");
        }
    }
    return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))

using namespace std;

const int inf = 1e9+7;
const int N = 1e5 + 50;

bool good[26];
char str[N];
char p[N];
int len;

bool vis[N];

bool allBad(){
    for(int i=0;p[i];++i){
        if((!vis[i])&&good[p[i]-'a']){
            return false;
        }
    }
    return true;
}

bool checkPre(){
    for(int i=0;str[i]&&str[i]!='*';++i){
        vis[i]=1;
        if(str[i]=='?'&&good[p[i]-'a']){
            continue;
        }
        if(str[i]!=p[i]){
            return false;
        }
    }
    return true;
}

bool checkSuffix(int pLen){
    int i=len-1;
    int j=pLen-1;
    for(;i>=0&&j>=0&&str[i]!='*';--i,--j){
        vis[j]=1;
        if(str[i]=='?'&&good[p[j]-'a']){
            continue;
        }
        if(str[i]!=p[j]){
            return false;
        }
    }
    return true;
}

bool query(){
    int lenP=strlen(p);
    fill(vis,vis+lenP,0);
    if(lenP<len-1){
        return false;
    }
    return (checkPre()&&checkSuffix(lenP)&&allBad());
}

int main(){
    //freopen("/home/lu/code/r.txt","r",stdin);
    //freopen("/home/lu/code/w.txt","w",stdout);
    while(~scanf("%s",str)){
        MEM(good,0);
        for(int i=0;str[i];++i){
            good[str[i]-'a']=1;
        }
        scanf("%s",str);
        len=strlen(str);
        int q;
        scanf("%d",&q);
        while(q--){
            scanf("%s",p);
            puts(query()?"YES":"NO");
        }
    }
    return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))

using namespace std;

const int inf = 1e9+7;
const int N = 1e5 + 50;

bool good[26];
char str[N];
char p[N];
int len;

int vis[N];

bool allBad(){
    for(int i=0;p[i];++i){
        if((!vis[i])&&good[p[i]-'a']){
            return false;
        }
        if(vis[i]>1){
            return false;
        }
    }
    return true;
}

bool checkPre(){
    for(int i=0;str[i]&&str[i]!='*';++i){
        vis[i]++;
        if(str[i]=='?'&&good[p[i]-'a']){
            continue;
        }
        if(str[i]!=p[i]){
            return false;
        }
    }
    return true;
}

bool checkSuffix(int pLen){
    int i=len-1;
    int j=pLen-1;
    for(;i>=0&&j>=0&&str[i]!='*';--i,--j){
        vis[j]++;
        if(str[i]=='?'&&good[p[j]-'a']){
            continue;
        }
        if(str[i]!=p[j]){
            return false;
        }
    }
    return true;
}

bool query(){
    int lenP=strlen(p);
    fill(vis,vis+lenP,0);
    if(lenP<len-1){
        return false;
    }
    return (checkPre()&&checkSuffix(lenP)&&allBad());
}

int main(){
    //freopen("/home/lu/code/r.txt","r",stdin);
    //freopen("/home/lu/code/w.txt","w",stdout);
    while(~scanf("%s",str)){
        MEM(good,0);
        for(int i=0;str[i];++i){
            good[str[i]-'a']=1;
        }
        scanf("%s",str);
        len=strlen(str);
        int q;
        scanf("%d",&q);
        while(q--){
            scanf("%s",p);
            puts(query()?"YES":"NO");
        }
    }
    return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))

using namespace std;

const int inf = 1e9+7;
const int N = 1e5 + 50;

bool good[26];
char str[N];
char p[N];
int len;

int pos;

void getStarPos(){
    int i;
    for(i=0;str[i];++i){
        if(str[i]=='*'){
            pos=i;
            return;
        }
    }
    str[i]='*';
    pos=i;
    str[i+1]=0;
}

bool allBad(char*s,int st,int ed){
    while(st<=ed){
        if(good[s[st]-'a']){
            return false;
        }
        ++st;
    }
    return true;
}

bool checkPre(int ed){
    for(int i=0;i<=ed;++i){
        if(str[i]=='?'&&good[p[i]-'a']){
            continue;
        }
        if(str[i]!=p[i]){
            return false;
        }
    }
    return true;
}

bool checkSuffix(int sufLen,int pLen){
    for(int k=0;k<sufLen;++k){
        int i=len-k;
        int j=pLen-k;
        if(i<0||j<0||str[i]!=p[j]){
            return false;
        }
    }
    return true;
}

bool query(){
    int lenP=strlen(p);
    return allBad(p,pos,lenP-len+pos)&&checkPre(pos-1)&&checkSuffix(len-1-pos,lenP);
}

int main(){
    //freopen("/home/lu/code/r.txt","r",stdin);
    //freopen("/home/lu/code/w.txt","w",stdout);
    while(~scanf("%s",str)){
        MEM(good,0);
        for(int i=0;str[i];++i){
            good[str[i]-'a']=1;
        }
        scanf("%s",str);
        getStarPos();
        len=strlen(str);
        int q;
        scanf("%d",&q);
        while(q--){
            scanf("%s",p);
            puts(query()?"YES":"NO");
        }
    }
    return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))

using namespace std;

const int inf = 1e9+7;
const int N = 1e5 + 50;

bool good[26];
char str[N];
char p[N];
int len;

int pos;

void getStarPos(){
    int i;
    for(i=0;str[i];++i){
        if(str[i]=='*'){
            pos=i;
            return;
        }
    }
    str[i]='*';
    pos=i;
    str[i+1]=0;
}

bool allBad(char*s,int st,int ed){
    while(st<=ed){
        if(good[s[st]-'a']){
            return false;
        }
        ++st;
    }
    return true;
}

bool checkPre(int ed){
    for(int i=0;i<=ed;++i){
        if(str[i]=='?'&&good[p[i]-'a']){
            continue;
        }
        if(str[i]=='?'&&good[p[j]-'a']){
            continue;
        }
        if(str[i]!=p[i]){
            return false;
        }
    }
    return true;
}

bool checkSuffix(int sufLen,int pLen){
    for(int k=0;k<sufLen;++k){
        int i=len-k-1;
        int j=pLen-k-1;
        if(i<0||j<0||str[i]!=p[j]){
            return false;
        }
    }
    return true;
}

bool query(){
    int lenP=strlen(p);
    if(lenP<len-1){
        return false;
    }
    return allBad(p,pos,lenP-len+pos)&&checkPre(pos-1)&&checkSuffix(len-1-pos,lenP);
}

int main(){
    //freopen("/home/lu/code/r.txt","r",stdin);
    //freopen("/home/lu/code/w.txt","w",stdout);
    while(~scanf("%s",str)){
        MEM(good,0);
        for(int i=0;str[i];++i){
            good[str[i]-'a']=1;
        }
        scanf("%s",str);
        getStarPos();
        len=strlen(str);
        int q;
        scanf("%d",&q);
        while(q--){
            scanf("%s",p);
            puts(query()?"YES":"NO");
        }
    }
    return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))

using namespace std;

const int inf = 1e9+7;
const int N = 1e5 + 50;

bool good[26];
char str[N];
char p[N];
int len;

bool vis[N];

bool allBad(){
    for(int i=0;p[i];++i){
        if(!vis[i]&&good[p[i]-'a']){
            return false;
        }
    }
    return true;
}

bool checkPre(){
    for(int i=0;str[i]&&str[i]!='*';++i){
        vis[i]=1;
        if(str[i]=='?'&&good[p[i]-'a']){
            continue;
        }
        if(str[i]!=p[i]){
            return false;
        }
    }
    return true;
}

bool checkSuffix(int pLen){
    for(int k=0;len-k-1>=0&&str[len-k-1]!='*';++k){
        int i=len-k-1;
        int j=pLen-k-1;
        if(i<0||j<0){
            break;
        }
        vis[j]=1;
        if(str[i]=='?'&&good[p[j]-'a']){
            continue;
        }
        if(str[i]!=p[j]){
            return false;
        }
    }
    return true;
}

bool query(){
    int lenP=strlen(p);
    fill(vis,vis+lenP,0);
    if(lenP<len-1){
        return false;
    }
    return checkPre()&&checkSuffix(lenP)&&allBad();
}

int main(){
    //freopen("/home/lu/code/r.txt","r",stdin);
    //freopen("/home/lu/code/w.txt","w",stdout);
    while(~scanf("%s",str)){
        MEM(good,0);
        for(int i=0;str[i];++i){
            good[str[i]-'a']=1;
        }
        scanf("%s",str);
        len=strlen(str);
        int q;
        scanf("%d",&q);
        while(q--){
            scanf("%s",p);
            puts(query()?"YES":"NO");
        }
    }
    return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))

using namespace std;

const int inf = 1e9+7;
const int N = 1e5 + 50;

bool good[26];
char str[N];
char p[N];
int len;
int vis[N];

void addStar(){
    int i=0;
    for(i=0;str[i];++i){
        if(str[i]=='*'){
            return;
        }
    }
    str[i]='*';
    str[i+1]=0;
}

bool allBad(){
    for(int i=0;p[i];++i){
        if((!vis[i])&&good[p[i]-'a']){
            return false;
        }
    }
    return true;
}

bool checkPre(){
    for(int i=0;str[i]&&str[i]!='*';++i){
        vis[i]++;
        if(str[i]=='?'&&good[p[i]-'a']){
            continue;
        }
        if(str[i]!=p[i]){
            return false;
        }
    }
    return true;
}

bool checkSuffix(int pLen){
    int i=len-1;
    int j=pLen-1;
    for(;i>=0&&j>=0&&str[i]!='*';--i,--j){
        vis[j]++;
        if(str[i]=='?'&&good[p[j]-'a']){
            continue;
        }
        if(str[i]!=p[j]){
            return false;
        }
    }
    return true;
}

bool query(){
    int lenP=strlen(p);
    fill(vis,vis+lenP,0);
    if(lenP<len-1){
        return false;
    }
    return (checkPre()&&checkSuffix(lenP)&&allBad());
}

int main(){
    //freopen("/home/lu/code/r.txt","r",stdin);
    //freopen("/home/lu/code/w.txt","w",stdout);
    while(~scanf("%s",str)){
        MEM(good,0);
        for(int i=0;str[i];++i){
            good[str[i]-'a']=1;
        }
        scanf("%s",str);
        addStar();
        len=strlen(str);
        int q;
        scanf("%d",&q);
        while(q--){
            scanf("%s",p);
            puts(query()?"YES":"NO");
        }
    }
    return 0;
}


#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))

using namespace std;

const int inf = 1e9+7;
const int N = 1e5 + 50;

bool good[26];
char str[N];
char p[N];
int len;

bool vis[N];

bool allBad(){
    for(int i=0;p[i];++i){
        if(!vis[i]&&good[p[i]-'a']){
            return false;
        }
    }
    return true;
}

bool checkPre(){
    for(int i=0;str[i]&&str[i]!='*';++i){
        if(str[i]=='?'&&good[p[i]-'a']){
            vis[i]=1;
            continue;
        }
        if(str[i]!=p[i]){
            return false;
        }
        vis[i]=1;
    }
    return true;
}

bool checkSuffix(int pLen){
    for(int k=0;len-k-1>=0&&str[len-k-1]!='*';++k){
        int i=len-k-1;
        int j=pLen-k-1;
        if(i<0||j<0){
            break;
        }
        if(str[i]=='?'&&good[p[j]-'a']){
            vis[i]=1;
            continue;
        }
        if(str[i]!=p[j]){
            return false;
        }
        vis[j]=1;
    }
    return true;
}

bool query(){
    int lenP=strlen(p);
    fill(vis,vis+lenP,0);
    if(lenP<len-1){
        return false;
    }
    return checkPre()&&checkSuffix(lenP)&&allBad();
}

int main(){
    //freopen("/home/lu/code/r.txt","r",stdin);
    //freopen("/home/lu/code/w.txt","w",stdout);
    while(~scanf("%s",str)){
        MEM(good,0);
        for(int i=0;str[i];++i){
            good[str[i]-'a']=1;
        }
        scanf("%s",str);
        len=strlen(str);
        int q;
        scanf("%d",&q);
        while(q--){
            scanf("%s",p);
            puts(query()?"YES":"NO");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[400];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);

    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		memset(str, '\0', sizeof(str));
    		cin>>str;
    		int len_str = strlen(str);
    		int number_star;
			if ( len_str < len_a )
			{
				if ( len_a - len_str > 1 )
				{
					cout<<"NO"<<endl;
					continue;
				}
				else{
					number_star = 0;
				}
			}
			else{
				number_star = len_str - len_a + 1;
			}
			if ( number_star == 0 )
			{
				if ( len_str != len_a )
				{
					cout<<"NO"<<endl;
					continue;
				}
			}
    		int cnt = 0;
    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a ; ++i)
    		{
    			if ( a[i] == str[j] )
    			{
    				j++;
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if ( isgood[str[j]] == true )
    					{
    						j++;
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*' )
    				{
    					cnt++;
    					if ( cnt > 1 )
    					{
    						RET = 0;
    						break;
    					}
    					int flag = 1;
    					for(int cnt = 0; cnt < number_star; ++cnt, ++j)
    					{
    						if( j > len_str )
    						{
    							flag = 0;
    							break;
							}
    						if ( isgood[str[j]] == false )
    						{
    							continue;
    						}
    						else{
    							flag = 0;
    							break;
    						}
    					}
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[400];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);

    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		memset(str, '\0', sizeof(str));
    		cin>>str;
    		int len_str = strlen(str);
    		int number_star;
			if ( len_str < len_a )
			{
				if ( len_a - len_str > 1 )
				{
					cout<<"NO"<<endl;
					continue;
				}
				else{
					number_star = 1;
				}
			}
			else{
				number_star = len_str - len_a + 1;
			}
    		int cnt = 0;
    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a ; ++i)
    		{
    			if ( a[i] == str[j] )
    			{
    				j++;
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if (  isgood[str[j]] == true )
    					{
    						j++;
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*' )
    				{
    					cnt++;
    					if ( cnt > 1 )
    					{
    						RET = 0;
    						break;
    					}
    					int flag = 1;
    					for(int cnt = 0; cnt < number_star; ++cnt, ++j)
    					{
    						if ( isgood[str[j]] == false )
    						{
    							continue;
    						}
    						else{
    							flag = 0;
    							break;
    						}
    					}
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[400];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);

    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		memset(str, '\0', sizeof(str));
    		cin>>str;
    		int len_str = strlen(str);
    		int number_star;
			if ( len_str < len_a )
			{
				if ( len_a - len_str > 1 )
				{
					cout<<"NO"<<endl;
					continue;
				}
				else{
					number_star = 1;
				}
			}
			else{
				number_star = len_str - len_a + 1;
			}

    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a ; ++i, ++j)
    		{
    			if ( a[i] == str[j] )
    			{
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if (  isgood[str[j]] == true )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*' )
    				{
    					int flag = 1;
    					for(int cnt = 0; cnt < number_star; ++cnt, ++j)
    					{
    						if ( isgood[str[j]] == false )
    						{
    							continue;
    						}
    						else{
    							flag = 0;
    							break;
    						}
    					}
    					j--;
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[400];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);

    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		memset(str, '\0', sizeof(str));
    		cin>>str;
    		int len_str = strlen(str);
    		int number_star;
			if ( len_str < len_a )
			{
				if ( len_a - len_str > 1 )
				{
					cout<<"NO"<<endl;
					continue;
				}
				else{
					number_star = 0;
				}
			}
			else{
				number_star = len_str - len_a + 1;
			}

    		int cnt = 0;
    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a || j < len_str; ++i)
    		{
    			if ( a[i] == str[j] )
    			{
    				j++;
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if ( isgood[str[j]] == true )
    					{
    						j++;
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*' )
    				{
    					cnt++;
    					if ( cnt > 1 )
    					{
    						RET = 0;
    						break;
    					}
    					int flag = 1;
    					for(int cnt = 0; cnt < number_star; ++cnt, ++j)
    					{
    						if( j > len_str )
    						{
    							flag = 0;
    							break;
							}
    						if ( isgood[str[j]] == false )
    						{
    							continue;
    						}
    						else{
    							flag = 0;
    							break;
    						}
    					}
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


n=int(input())
z=[]
for i in range(0,n):
	z.append(0)
	a=input()
	b=a.split(" ")
	for k in range(0,4):
		b[k]=int(b[k])

	for j in range(1,b[2]):
		if(j%b[1]==0):
			z[i]+=1
	for g in range(b[3]+1,b[0]+1):
		if(g%b[1]==0):
			z[i]+=1
for o in range(0,n):
	print(z[o])


k=int(input())
for i in range(k):
    L,v,l,r=map(int,input().split())
    n=(L)//v
    m=(r-l)//v
    if r%v==0 or l%v==0:
        m=m+1
    print(n-m)


k=int(input())
for i in range(k):
    L,v,l,r=map(int,input().split())
    n=(L)//v
    m=(r-l)//v
    if r%v==0 or l%v==0:
        m=m+1
    if L==1 and v==1:
        print(1)
    elif L==1 and v!=1:
        print(0)
    else:

        print(n-m)


k=int(input())
for i in range(k):
    L,v,l,r=map(int,input().split())
    print(L//v-r//v+(l-1)//v)


k=int(input())
for i in range(k):
    L,v,l,r=map(int,input().split())
    n=(L)//v
    m=(r-l)//v
    if(r==l):
        m=1
    if r%v==0 or l%v==0:
        m=m+1
    if L==1 and v==1:
        print(1)
    elif L==1 and v!=1:
        print(0)
    else:
        if(n-m<0):
            print(0)
        else:
            print(n-m)


k=int(input())
for i in range(k):
    L,v,l,r=map(int,input().split())
    n=(L)//v
    m=(r-l)//v
    if(r==l):
        m=1
    if r%v==0 or l%v==0:
        m=m+1
    if L==1 and v==1:
        print(1)
    elif L==1 and v!=1:
        print(0)
    else:

        print(n-m)


k=int(input())
for i in range(k):
    L,v,l,r=map(int,input().split())
    n=(L)//v
    m=(r-l)//v

    if r%v==0 or l%v==0:
        m=m+1
    if L==1 and v==1:
        print(1)
    elif L==1 and v!=1:
        print(0)
    else:
        if(n-m<0):
            print(0)
        else:
            print(n-m)


k=int(input())
for i in range(k):
    L,v,l,r=map(int,input().split())
    n=(L)//v
    m=(r-l)//v

    if r%v==0 or l%v==0:
        m=m+1
    if L==1 and v==1:
        if l==1 or r==1:
            print(0)
        else:
            print(1)
    elif L==1 and v!=1:
        print(0)
    else:
        if(n-m<0):
            print(0)
        else:
            print(n-m)


t_ = list(map(int, input().split(sep=' ')))
t = t_[0]

for i in range(t):
    L, v, l, r = list(map(int, input().split(sep=' ')))
    num = (L-1)//v

    not_seen = (l - r) // v

    if(l%v==0):
        not_seen+=1

    print(str(num-not_seen))


t_ = list(map(int, input().split(sep=' ')))
t = t_[0]

for i in range(t):
    L, v, l, r = list(map(int, input().split(sep=' ')))
    num = L//v

    not_seen = (r-l) // v

    if(l%v==0):
        not_seen+=1

    print(str(num-not_seen))


t_ = list(map(int, input().split(sep=' ')))
t = t_[0]

for i in range(t):
    L, v, l, r = list(map(int, input().split(sep=' ')))
    num = (L-1)//v
    not_seen = (r-l)//v

    print(str(num-not_seen))


t_ = list(map(int, input().split(sep=' ')))
t = t_[0]

for i in range(t):
    L, v, l, r = list(map(int, input().split(sep=' ')))
    num = (L-1)//v

    if(l%v==0):
        not_seen = (r-l)//v
        not_seen+=1
    else:
        not_seen = (r - l) // v

    print(str(num-not_seen))


t_ = list(map(int, input().split(sep=' ')))
t = t_[0]

for i in range(t):
    L, v, l, r = list(map(int, input().split(sep=' ')))
    num = (L-1)//v

    not_seen = (r-l) // v

    if(l%v==0):
        not_seen+=1

    print(str(num-not_seen))


t_ = list(map(int, input().split(sep=' ')))
t = t_[0]

for i in range(t):
    L, v, l, r = list(map(int, input().split(sep=' ')))
    num = L//v

    not_seen = (r//v) - (l//v)

    if(l%v==0):
        not_seen+=1

    print(str(num-not_seen))


t_ = list(map(int, input().split(sep=' ')))
t = t_[0]

for i in range(t):
    L, v, l, r = list(map(int, input().split(sep=' ')))
    num = L//v

    not_seen = (l - r) // v

    if(l%v==0):
        not_seen+=1

    print(str(num-not_seen))


q_ = list(map(int, input().split(sep=' ')))
q= q_[0]

books = {}
for i in range(q):

    command = input()
    d = command[:command.index(' ')]
    numb = int(command[command.index(' ')+1:])

    if(len(books)!=0):
        if(d=="L"):
            books = books.insert(0,numb)
        else:
            if(d=='R'):
                books = books.append(numb)
            else:
                l = books.index(numb)
                r = len(books) - books.index(numb) - 1
                print(str(min(l,r)))
    else:
        books.append(numb)


a = [int(x) for x in input().split()]
b = str(input())
remain = str(10**a[2])
b = b[a[0] - a[1]:]
x = 0
count = 0
while x < len(b):
    if x < len(remain):
        if remain[(-1-x)] != b[-1-x]:
            count += 1
    else:
        if b[-1-x] == "1":
            count += 1
    x += 1
print(count)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 14 13:35:44 2018

@author: abhinavvajpeyi)
"""
#def search()
n=int(input())
while n:
    d,v,l,r=input().strip().split(' ')
    d=int(d)
    v=int(v)
    l=int(l)
    r=int(r)
    count=0
    li=[]
    for i in range(1,d+1):
        if i%v==0:
            if i<l or i>r:
                count+=1

#print(li)
    print(count)
    n-=1


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 14 13:35:44 2018

@author: abhinavvajpeyi)
"""
#def search()
n=int(input())
while n:
    d,v,l,r=input().strip().split(' ')
    d=int(d)
    v=int(v)
    l=int(l)
    r=int(r)
    count=0
    li=[]
    for i in range(1,d+1):
        if i%v==0:
            li.append(i)

    for i in li:
        if i<l or i>r:
            count+=1

#print(li)
    print(count)
    n-=1


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 14 13:35:44 2018

@author: abhinavvajpeyi)
"""
#def search()
n=int(input())
d,v,l,r=input().strip().split(' ')
d=int(d)
v=int(v)
l=int(l)
r=int(r)
count=0
li=[]
for i in range(1,d+1):
    if i%v==0:
        li.append(i)

for i in li:
    if i<l or i>r:
        count+=1

#print(li)
print(count)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 14 13:35:44 2018

@author: abhinavvajpeyi)
"""
def search(l,h,v):
    if l%v==0:
        return ((h//v)-(l//v)+1)
    return ((h//v)-(l//v))
n=int(input())
while n:
    d,v,l,r=input().strip().split(' ')
    d=int(d)
    v=int(v)
    l=int(l)
    r=int(r)
    count=0
    total=search(1,d,v)
    less=search(l,r,v)
    print(total-less)

    n-=1


t=int((input()))
while(t):
    L,v,l,r=map(int,input().split())
    if(v==0):
        print("0")
    else:
        L = L // v
        if (l % v == 0):
            l = l // v
            r = r // v
            r += 1
        else:
            l = l // v
            r = r // v
        print(L + l - r)
        t = t - 1


t=int((input()))
while(t):
    L,v,l,r=map(int,input().split(" "))
    if(v==0):
        print("0")
    else:
        L = L // v
        if (l % v == 0 or r % v == 0):
            l = l // v
            r = r // v
            r += 1
        else:
            l = l // v
            r = r // v
        print(L + l - r)
        t = t - 1


t = int(input())
for _ in range(t):
    L,v,l,r = map(int,input().split())
    if(r == l and r % v == 0):
        print(max(L//v - 1,0))
    else:
        print(max(L//v - (r - l + 1) //v,0))
    print()


t = int(input())
for _ in range(t):
    L,v,l,r = map(int,input().split())

    if(v > r):
        print(L//v)
    elif(v < l):
        print(L//v - (r - l + 1) //v)
    else:
        print(L//v - r//v)


t = int(input())
for _ in range(t):
    L,v,l,r = map(int,input().split())
    mod = l%v;
    if(mod == 0):
        print(L//v - (r - l) //(v) - 1)
    else:
        print(L//v - (r-l+mod)//v)


n = int(input())

def func(a, b, c ,d):
  res = a//b+c//b-d//b
  if c%b==0 or d%b==0:
    res-=1
  return res

for i in range(n):
  L, v, r, l = list(map(int, input().split()))
  print(func(L, v, r, l))


n = int(input())

def func(a, b, c ,d):
  res = a//b-(d-c)//b
  if c%b==0 or d%b==0:
    res-=1
  return res

for i in range(n):
  L, v, r, l = list(map(int, input().split()))
  print(func(L, v, r, l))


n = int(input())

def func(a, b, c ,d):
  res = a//b-(d//b-(c-1)//b)
  return res

for i in range(n):
  L, v, r, l = list(map(int, input().split()))
  print(func(L, v, r, l))


#!/usr/bin/env python

t = input()
for line in range(int(t)):
    numbers = input().split()
    L = int(numbers[0])
    v = int(numbers[1])
    l = int(numbers[2])
    r = int(numbers[3])

    p = 0

    for point in range(1,l):
        if point%v==0:
            p += 1
    for point in range(r+1,L+1):
        if point%v==0:
            p += 1

    print(p)


#!/usr/bin/env python

t = input()
for line in range(int(t)):
    numbers = input().split()
    L = int(numbers[0])
    v = int(numbers[1])
    l = int(numbers[2])
    r = int(numbers[3])

    totalLanterns = L//v
    trainLanterns = (r//v) - ((l-1)//v)

    p = totalLanterns - trainLanterns

    print(p)


#!/usr/bin/env python

with open('q.txt') as input:
    t = input.readline()
    for line in range(int(t)):
        numbers = input.readline().split()
        L = int(numbers[0])
        v = int(numbers[1])
        l = int(numbers[2])
        r = int(numbers[3])

        p = 0

        for point in range(1,l):
            if point%v==0:
                p += 1
        for point in range(r+1,L+1):
            if point%v==0:
                p += 1

        print(p)


t = int(input())
for t_itr in range (t):
    pqrs = input().rstrip().split()
    p = int(pqrs[0])
    q = int(pqrs[1])
    r = int(pqrs[2])
    s = int(pqrs[3])
    lantern = (p // q) - (s // q) + ((r - 1) // q)
    print(lantern)


def main():
	t = int(input())
	for t_itr in range (t):
		pqrs = input().rstrip().split()
		p = int(pqrs[0])
		q = int(pqrs[1])
		r = int(pqrs[2])
		s = int(pqrs[3])
		res = solve(p, q, r, s)

def solve(p, q, r, s):
	b = []
	c = []
	count = 0
	for i in range(1, t[0] + 1):
		b.append(i)
	for k in range(t[2], t[3] + 1):
		c.append(k)
	for j in range(t[1], t[0] + 1, t[1]):
		if j in b and j not in c:
			count += 1
	print (count)

if __name__ == '__main__':
	main()


def main():
	t = int(input())
	for t_itr in range (t):
		pqrs = input().rstrip().split()
		p = int(pqrs[0])
		q = int(pqrs[1])
		r = int(pqrs[2])
		s = int(pqrs[3])
		res = solve(p, q, r, s)

def solve(p, q, r, s):
	b = []
	c = []
	count = 0
	for i in range(1, t[0] + 1):
		b.append(i)
	for k in range(t[2], t[3] + 1):
		c.append(k)
	for j in range(t[1], t[0] + 1, t[1]):
		if j in b and j not in c:
			count += 1
	print count

if __name__ == '__main__':
	main()


def countDiv(A, B, M):
    if (A % M == 0):
        return ((B //M) - (A //M)) + 1
    return ((B //M) - (A //M))

for i in range(int(input())):
    n,m,l,r=map(int,input().split())
    if l==1 and r==n:
        print(0)
    else:
        print(countDiv(1,l-1,m)+countDiv(r+1,n,m))


for i in range(int(input())):
    n,m,l,r=map(int,input().split())
    if l==1 and r==n:
        print(0)
    else:
        c=0
        for i in range(1,n+1):
            if i%m==0 and (i<l or i>r):
                c+=1
        print(c)


for i in range(int(input())):
    n,m,l,r=map(int,input().split())
    if l==1 and r==n:
        print(0)
    else:
        c=0
        for i in range(1,n+1):
            if i%m==0:
                if (i<l or i>r):
                    c+=1
        print(c)


n = int(input())
a = []
for p in range(n):
    L, v, l, r = map(int, input().split())
    kv = L // v
    kn = r // v - (l - 1) // v
    k = kv - kn
    a.append(k)
for q in a:
    print(q)


n = int(input())
a = []
import math
for p in range(n):
    L, v, l, r = map(int, input().split())
    k = 0
    if L == r:
        k = 0
        a.append(k)
        continue
    kv = L // v
    kn = r // v - (l - 1) // v
    k = kv - kn
    a.append(k)
for q in a:
    print(q)


n = int(input())
a = []
for p in range(n):
    L, v, l, r = map(int, input().split())
    k = 0
    if L == r:
        k = 0
        a.append(k)
        continue
    for i in range(0+v,L+1,v):
        if i < l or i > r:
            k += 1
    a.append(k)
for q in a:
    print(q)


import math

t = int(input())
Lvlr = []
output = ''
for i in range(t):
    Lvlr.append(list(map(int, input().split(' '))))
for i in range(t-1):
    seeLantern = 0
    if(Lvlr[i][2]%Lvlr[i][1] == 0):
        seeLantern += int(Lvlr[i][2]/Lvlr[i][1]) - 1
    else:
        seeLantern += int(Lvlr[i][2]/Lvlr[i][1])
    if(Lvlr[i][3]%Lvlr[i][1] == 0):
        seeLantern += int((Lvlr[i][0] - Lvlr[i][3])/Lvlr[i][1])
    else:
        r = math.ceil(Lvlr[i][3]/Lvlr[i][1]) * Lvlr[i][1]
        seeLantern += int ((Lvlr[i][0] - r)/Lvlr[i][1]) + 1
    output += str(seeLantern) + '\n'
seeLantern = 0
if(Lvlr[-1][2]%Lvlr[-1][1] == 0):
    seeLantern += int(Lvlr[-1][2]/Lvlr[-1][1]) - 1
else:
    seeLantern += int(Lvlr[-1][2]/Lvlr[-1][1])
if(Lvlr[-1][3]%Lvlr[-1][1] == 0):
    seeLantern += int((Lvlr[-1][0] - Lvlr[-1][3])/Lvlr[-1][1])
else:
    r = math.ceil(Lvlr[-1][3]/Lvlr[-1][1]) * Lvlr[-1][1]
    seeLantern += int((Lvlr[-1][0] - r)/Lvlr[-1][1]) + 1
output += str(seeLantern)
print(output)


import math

t = int(input())
Lvlr = []
output = ''
Lvlr = [[913338581, 325436058, 378430701, 728704378]]
# for i in range(t):
#     Lvlr.append(list(map(int, input().split(' '))))
for i in range(t-1):
    seeLantern = 0
    if(Lvlr[i][2]%Lvlr[i][1] == 0):
        seeLantern += int(Lvlr[i][2]/Lvlr[i][1]) - 1
    else:
        seeLantern += int(Lvlr[i][2]/Lvlr[i][1])
    if(Lvlr[i][3]%Lvlr[i][1] == 0):
        seeLantern += int((Lvlr[i][0] - Lvlr[i][3])/Lvlr[i][1])
    else:
        r = math.ceil(Lvlr[i][3]/Lvlr[i][1]) * Lvlr[i][1]
        if(r<=Lvlr[i][0]):
            seeLantern += int ((Lvlr[i][0] - r)/Lvlr[i][1]) + 1
    output += str(seeLantern) + '\n'
seeLantern = 0
if(Lvlr[-1][2]%Lvlr[-1][1] == 0):
    seeLantern += int(Lvlr[-1][2]/Lvlr[-1][1]) - 1
else:
    seeLantern += int(Lvlr[-1][2]/Lvlr[-1][1])
if(Lvlr[-1][3]%Lvlr[-1][1] == 0):
    seeLantern += int((Lvlr[-1][0] - Lvlr[-1][3])/Lvlr[-1][1])
else:
    r = math.ceil(Lvlr[-1][3]/Lvlr[-1][1]) * Lvlr[-1][1]
    if(r<=Lvlr[-1][0]):
        seeLantern += int((Lvlr[-1][0] - r)/Lvlr[-1][1]) + 1
output += str(seeLantern)
print(output)


import math

t = int(input())
Lvlr = []
output = ''
for i in range(t):
    Lvlr.append(list(map(int, input().split(' '))))
for i in range(t-1):
    seeLantern = 0
    if(Lvlr[i][2]%Lvlr[i][1] == 0):
        seeLantern += int(Lvlr[i][2]/Lvlr[i][1]) - 1
    else:
        seeLantern += int(Lvlr[i][2]/Lvlr[i][1])
    if(Lvlr[i][3]%Lvlr[i][1] == 0):
        seeLantern += int((Lvlr[i][0] - Lvlr[i][3])/Lvlr[i][1])
    else:
        r = math.ceil(Lvlr[i][3]/Lvlr[i][1]) * Lvlr[i][1]
        if(r<=Lvlr[i][0]):
            seeLantern += int ((Lvlr[i][0] - r)/Lvlr[i][1]) + 1
    output += str(seeLantern) + '\n'
seeLantern = 0
if(Lvlr[-1][2]%Lvlr[-1][1] == 0):
    seeLantern += int(Lvlr[-1][2]/Lvlr[-1][1]) - 1
else:
    seeLantern += int(Lvlr[-1][2]/Lvlr[-1][1])
if(Lvlr[-1][3]%Lvlr[-1][1] == 0):
    seeLantern += int((Lvlr[-1][0] - Lvlr[-1][3])/Lvlr[-1][1])
else:
    r = math.ceil(Lvlr[-1][3]/Lvlr[-1][1]) * Lvlr[-1][1]
    if(r<=Lvlr[-1][0]):
        seeLantern += int((Lvlr[-1][0] - r)/Lvlr[-1][1]) + 1
output += str(seeLantern)
print(output)


import math

t = int(input())
Lvlr = []
output = ''
for i in range(t):
    Lvlr.append(list(map(int, input().split(' '))))

for i in range(t-1):
    seeLantern = 0
    if(Lvlr[i][2]%Lvlr[i][1] == 0):
        seeLantern += int(Lvlr[i][2]/Lvlr[i][1]) - 1
    else:
        seeLantern += int(Lvlr[i][2]/Lvlr[i][1])
    if(Lvlr[i][3]%Lvlr[i][1] == 0):
        seeLantern += int((Lvlr[i][0] - Lvlr[i][3])/Lvlr[i][1])
    else:
        r = math.ceil(Lvlr[i][3]/Lvlr[i][1]) * Lvlr[i][1]
        seeLantern += int ((Lvlr[i][0] - r)/Lvlr[i][1]) + 1
    output += str(seeLantern) + '\n'
seeLantern = 0
if(Lvlr[-1][2]%Lvlr[-1][1] == 0):
    seeLantern += int(Lvlr[-1][2]/Lvlr[-1][1]) - 1
else:
    seeLantern += int(Lvlr[-1][2]/Lvlr[-1][1])
if(Lvlr[-1][3]%Lvlr[-1][1] == 0):
    seeLantern += int((Lvlr[-1][0] - Lvlr[-1][3])/Lvlr[-1][1])
else:
    r = math.ceil(Lvlr[-1][3]/Lvlr[-1][1]) * Lvlr[-1][1]
    seeLantern += int ((Lvlr[-1][0] - r)/Lvlr[-1][1]) + 1
output += str(seeLantern)
print(output)


t=int(input())
def countDivisibles(A, B, M):

    # Add 1 explicitly as A is divisible by M
    if (A % M == 0):
        return ((B // M) - (A // M)) + 1

    # A is not divisible by M
    return ((B // M) - (A // M))
for i in range(t):
    L,v,l,r=map(int,input().split())
    k=countDivisibles(l,r,v)
    m=L//v
    print(int(m-k))


t=int(input())
for i in range(t):
    L,v,l,r=map(int,input().split())
    k=(r-l+1)//v
    m=L//v
    if(k==0):
        print(m-k-1)
    else:
        print(m-k)


t=int(input())
def countDivisibles(A, B, M):

    # Add 1 explicitly as A is divisible by M
    if (A % M == 0):
        return ((B / M) - (A / M)) + 1

    # A is not divisible by M
    return ((B / M) - (A / M))
for i in range(t):
    L,v,l,r=map(int,input().split())
    k=countDivisibles(l,r,v)
    m=L//v
    print(int(m-k))


t = int(input())
a = list()
while t > 0:
    L, v, l, r = input().split()
    L = int(L)
    v = int(v)
    l = int(l)
    r = int(r)
    t -= 1
    if l % v != 0:
        l = ((l // v) + 1) * v
    if r % v != 0:
        r -= r % v
    a.append(L // v - ((r - l) // v + 1))
for ans in a:
    print(ans)


t = int(input())
a = list()
while t > 0:
    L, v, l, r = input().split()
    L = int(L)
    v = int(v)
    l = int(l)
    r = int(r)
    t -= 1
    if l - r == 0:
        a.append((L // v) - 1)
        continue
    a.append((L // v) - (r - l + 1) // v)
for ans in a:
    print(ans)


#import numpy as np
k = int (input())

while (k):
    L,V,L2,R =  map(int,input().split())

    if (R-L2 > 1):
        res = (L)//V - (R-L2+1)//V
    else:
        res = (L)//V - (R)//V

    print (res)
    k -= 1


#import numpy as np
k = int (input())

while(k):
    L,V,L2,R =  map(int,input().split())
    res = (L//V)-(R//V-(L2-1)//V)
    k -= 1
    print (res)


#import numpy as np
k = int (input())
L,V,L2,R =  map(int,input().split())

while(k):
    res = (L//V)-(R//V-(L2-1)//V)
    k -= 1
    print (res)


#import numpy as np
k = int (input())

while (k):
    L,V,L2,R =  map(int,input().split())

    if ((R-L2) % 2 == 0 and (R-L2) !=0 ): res =(L // V) - (R-L2) // V
    else: res =(L // V) - (R-L2) // V - 1
    print (res)
    k -= 1


#import numpy as np
k = int (input())

while (k):
    L,V,L2,R =  map(int,input().split())

    if (R==L2 and R == V):
        res = L // V
        res -= 1
        print (res)
    else:
        res = L // V
        res2 = (R-L2+1) // V
        print (res-res2)
    k -= 1


t=int(input())
for i in range(t):
    a=input()
    L,v,l,r=int(a.split()[0]),int(a.split()[1]),int(a.split()[2]),int(a.split()[3])
    x=0
    x=L//v
    s=0
    if(l%v==0):
        print(x+l//v-r//v-1)
    else:
        print(x+l//v-r//v)


t=int(input())
for i in range(t):
    a=input()
    L,v,l,r=int(a.split()[0]),int(a.split()[1]),int(a.split()[2]),int(a.split()[3])
    x=0
    x=L//v
    x1=l//v
    x2=r//v
    if(l%v==0 or r%v==0):
        x=x-1
    print(x-(x2-x1))


for t in range(int(input().strip())):
	L,v,l,r = map(int,input().strip().split())
	n = L//v
	cns = 0
	if l==r:
		cns = l//v
	else:
		cns = (r-l+1)//v
	print(n-cns)


for t in range(int(input().strip())):
	L,v,l,r = map(int,input().strip().split())
	n = L//v
	cns = 0
	if l==r:
		cns = l//v
	if v==2:
		cns = (r-l)//v
	else:
		cns = (r-l-1)//v
		if l%v==0:
			cns+=1
		if r%v==0:
			cns+=1
	print(n-cns)


def coun(a,b,m):
	if a%m==0:
		return (b//m)-(a//m)+1
	return (b//m)-(a//m)

for t in range(int(input().strip())):
	L,v,l,r = map(int,input().strip().split())
	n = L//v
	cns = coun(l,r,v)
	print(n-cns)


n=int(input())
A=[]
cont=0
for i in range(n):
    a=list(map(int,input().split()))
    A+=a

for i in range(0,n):

    cont=0
    cont+=A[4*i]//A[4*i+1]

    cont-= ( ((A[4*i+3])//A[4*i+1])-((A[4*i+2]-1)//A[4*i+1]))

    print(cont)


n=int(input())
A=[]
cont=0
for i in range(n):
    a=list(map(int,input().split()))
    A+=a

for i in range(n):
    cont=0
    cont+=A[n*i]//A[n*i+1]

    for j in range (A[n*i+2],A[n*i+3]+1):
        if j%A[n*i+1]==0:
            cont=cont-(A[n*i+3]-j)//A[n*i+1]
            cont-=1
            break

    print(cont)


n=int(input())
A=[]
cont=0
for i in range(n):
    a=list(map(int,input().split()))
    A+=a

for i in range(n):
    cont=0
    cont+=A[n*i]//A[n*i+1]

    cont-= ( ((A[n*i+3])//A[n*i+1])-((A[n*i+2]-1)//A[n*i+1]))

    print(cont)


for i in range(int(input())):
    L,v,l,r=map(int,input().split())
    ans=L//v
    if (l % v == 0):
        ans-= ((r/ v) - (l / v)) + 1
    else:
        ans-= ((r / v) - (l / v))
    print(int(ans))


for i in range(int(input())):
    L,v,l,r=map(int,input().split())
    ans=L//v
    if(l==r and l%v==0):
        ans-=1
    else:
        ans-=(r-l+1)//v
    print(ans)


import math
for i in range(int(input())):
    L,v,l,r=map(int,input().split())
    print(math.ceil(L/v) -math.ceil(r/v)+math.ceil(l-1/v))


for i in range(int(input())):
    L,v,l,r=map(int,input().split())
    print(int(L//v - r//v + (l-1)//v))


for i in range(int(input())):
    L,v,l,r=map(int,input().split())
    ans=0
    for i in range(1,L+1):
        if(i%v==0):
            if(not(i>=l and i<=r)):
                ans+=1
    print(ans)


n=int(input())
for i in range(n):
    L,v,l,r=[int(i) for i in input().split()]
    st=L//v
    hu=(r-l+1)
    if hu < v:
        if l%v==0 or r % v==0:
            st-=1
    else:
        st=st-hu//v
    print(st)


n=int(input())
for i in range(n):
    L,v,l,r=[int(i) for i in input().split()]
    otv=(L-(r-l))//v
    if r%v==0 or l%v==0:
        otv-=1
    print(otv)


n=int(input())
for i in range(n):
    L,v,l,r=[int(i) for i in input().split()]
    st=L//v
    hu=(r-l+1)//v
    if hu==0 and (r%v==0 or l%v==0):
        hu+=1
    print(st-hu)


n=int(input())
for i in range(n):
    L,v,l,r=[int(i) for i in input().split()]
    x=L//v
    x2=r//v
    x3=(l-1)//v
    print(x-(x2-x3))


def ii():return int(input())
def mi():return map(int,input().split())
def li():return list(mi())
def si():return input()
t=ii()
while(t):
    t-=1
    L,v,l,r=mi()
    x=L//v
    l+=l%v
    if(l<=r):
       # print(x,l,r)
        y=1
        y+=(r-l)//v
        print(x-y)
    else:
        print(x)


def ii():return int(input())
def mi():return map(int,input().split())
def li():return list(mi())
def si():return input()
t=ii()
while(t):
    t-=1
    L,v,l,r=mi()
    x=L//v
    l+=(v-l%v)
    if(l<=r):
        if(x==0):
            print('0')
        else:
            y=1
            y+=(r-l)//v
            print(x-y)
    else:
        print(x)


def ii():return int(input())
def mi():return map(int,input().split())
def li():return list(mi())
def si():return input()
t=ii()
while(t):
    t-=1
    L,v,l,r=mi()
    x=L//v
    if(l%v):
        l+=(v-l%v)
    if(l<=r):
        if(x==0):
            print('0')
        else:
            y=1
            y+=(r-l)//v
            print(x-y)
    else:
        print(x)


def ii():return int(input())
def mi():return map(int,input().split())
def li():return list(mi())
def si():return input()
t=ii()
while(t):
    t-=1
    L,v,l,r=mi()
    x=L//v
    l+=l%v
    if(l<=r):
        #print(x,l,r)
        if(x==0):
            print('0')
        else:
            y=1
            y+=(r-l)//v
            print(x-y)
    else:
        print(x)


n = int(input())
for i in range(n):
    k,per,a,b=map(int,input().split())
    sum = k // per
    a1 = a // per
    b1 = b // per
    if b % per == 0:
       b1+=1
    print(sum - b1 + a1)


n = int(input())
for i in range(n):
    k,per,a,b=map(int,input().split())
    if per > k:
        print(0)
        continue
    if per <= a or per <= b:
        a += a % per
        b -= b % per
        err = ((max(a,b) - min(a,b)) // per)
        err+=1
        #print("3##",err)
        print(max((k // per )- err,0))
    else:
        print(k // per)


n = int(input())
for i in range(n):
    k,per,a,b=map(int,input().split())
    a+= a % per
    b-= b % per
    err = ((max(a,b) - min(a,b)) // per)+ 1
    print(k // per - err)


n = int(input())
for i in range(n):
    k,per,a,b=map(int,input().split())
    aa= a
    bb= b
    if per > k:
        print(0)
        continue
    if (per <= a or per <= b ) and (min(a,b) <= k):
        a += a % per
        b -= b % per
        if a > bb or b < aa:
            print(k // per)
            continue
        tmp = (b - a) // per
        tmp+=1
        print((k // per ) - tmp)
    else:
        print(k // per)


n = int(input())
for i in range(n):
    k,per,a,b=map(int,input().split())
    aa= a
    bb= b
    if per > k:
        print(0)
        continue
    if b >= k-(k % per) and a <= per:
        print(0)
        continue
    sum = k // per
    a1 = a // per
    ans = (b // per )- a1
    #print("###" , a1,ans)
    print(sum - ans)


n = int(input())
for i in range(n):
    k,per,a,b=map(int,input().split())
    aa= a
    bb= b
    if per > k:
        print(0)
        continue
    if b >= k-(k % per) and a <= per:
        print(0)
        continue
    sum = k // per
    a1 = a // per
    ans = (b // per ) - a1
    if a % per == 0 and b % per == 0:
        ans +=1
    #print("###" , a1,ans)
    print(sum - ans)


n = int(input())
for i in range(n):
    k,per,a,b=map(int,input().split())
    aa= a
    bb= b
    if per > k:
        print(0)
        continue
    if b >= k-(k % per) and a <= per:
        print(0)
        continue
    sum = k // per
    a1 = a // per
    ans = (b // per ) - a1
    if a % per == 0 or b % per == 0:
        ans +=1
    #print("###" , a1,ans)
    print(sum - ans)


n = int(input())
for i in range(n):
    k,per,a,b=map(int,input().split())
    sum = k // per
    a1 = (a-1) // per
    b1 = (b-1) // per
    if b % per == 0:
       b1+=1
    print(sum - b1 + a1)


n = int(input())
for i in range(n):
    k,per,a,b=map(int,input().split())
    sum = k // per
    a1 = a // per
    b1 = b // per
    if b % per == 0:
        b1+=1
    #print("###" , a1,ans)
    print(sum - b1 + a1)


# ANSHUL GAUTAM
# IIIT-D

from math import *
from string import *
from itertools import *

'''
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000
'''

T = int(input())
for _ in range(T):
	ans = 0
	destination,v,starting,ending = map(int, input().split())
	total = destination//v
	a = ending//v
	b = (starting-1)//v
	ans = total - a + b
	print(ans)


# ANSHUL GAUTAM
# IIIT-D

from math import *
from string import *
from itertools import *

'''
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000
'''

T = int(input())
for _ in range(T):
	desitination,v,starting,ending = map(int, input().split())
	if(starting==1 and ending==desitination):
		print(0)
	else:
		ans = 0
		for i in range(v,desitination+1,v):
			if(i<starting or i>ending):
				ans += 1
		print(ans)


# ANSHUL GAUTAM
# IIIT-D

from math import *
from string import *
from itertools import *

'''
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000
'''

T = int(input())
for _ in range(T):
	ans = 0
	destination,v,starting,ending = map(int, input().split())
	a = (starting)//v
	b = (destination-ending)//v
	if(starting%v == 0):
		a -= 1
	if(ending%v ==0):
		b -= 1
	print(max(0,a+b+1))


# ANSHUL GAUTAM
# IIIT-D

from math import *
from string import *
from itertools import *

'''
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000
'''

T = int(input())
for _ in range(T):
	ans = 0
	destination,v,starting,ending = map(int, input().split())
	a = max(0,(starting-1)//v)
	b = max(0,(destination-ending-1)//v)
	if(destination%v == 0 and destination!=ending):
		ans += 1
	ans += a+b
	print(ans)


t = int(input())
for i in range(t):
	L, v, l, r = map(int, input().split())
	print(L//v - (r//v - l//v + 1) if l%v == 0 and r%v == 0 else L//v - (r//v - l//v))


t = int(input())
for i in range(t):
	L, v, l, r = map(int, input().split())
	print(L//v - (r//v - (l-1)//v))


t = int(input())
for i in range(t):
	L, v, l, r = map(int, input().split())
	print(L//v - (r//v - l//v + 1) if l%v == 0 or r%v == 0 else L//v - (r//v - l//v))


import math
for _ in range(int(input())):
    a,b,c,d = list(map(int,input().split()))
    count = a//b
    #print(count)
    if c%b==0 and d%b==0:
        count = count+c//b-d//b-1
    elif c%b==0 and d%b!=0:
        count = count+c//b-math.ceil(d/b)
        #print(count)
    elif c%b!=0 and d%b==0:
        count = count+c//b-d//b
    else:
        count = count+c//b-d//b
    print(count)


for _ in range(int(input())):
    a,b,c,d = list(map(int,input().split()))
    count = a//b
    if c%b==0 or d%b==0:
        count = count+c//b-d//b-1
    else:
        count = count+c//b-d//b
    print(count)


import math
for _ in range(int(input())):
    a,b,c,d = list(map(int,input().split()))
    count = a//b
    count = count+c//b-math.ceil(d//b)
    if c%b==0 and d%b==0:
        count-=1
    print(count)


import math
for _ in range(int(input())):
    a,b,c,d = list(map(int,input().split()))
    count = a//b
    count = count+c//b-math.ceil(d/b)
    if c%b==0 and d%b==0:
        count-=1
    print(count)


n = int(input())
for i in range(n):
    L, v, l, r = map(int, input().split())

    l_mod = l % v

    if l % v != 0:
        l += (v - l_mod)

    if r % v != 0:
        r -= r % v

    dist = 0
    if l <= r:
        dist = (r - l) // v + 1

    print(L // v - dist)


n = int(input())
for i in range(n):
    L, v, l, r = map(int, input().split())
    d1 = L
    d2 = r - l + 1

    x1 = d1 // v
    x2 = d2 // v

    w = x1 - x2
    if l <= v <= r and x2 == 0:
        w -= 1
    print(w)


#include<bits/stdc++.h>
using namespace std;
int main(){
    long int t;
    cin>>t;
    for(long int i=0;i<t;i++){
        long int n,g,s,b;
        cin>>n;
        long int arr[n];
        for(long int j=0;j<n;j++){
            cin>>arr[j];
        }
        if(n<10){
            cout<<"0 0 0"<<endl;
        }
        else{
                if(n%2==0){
                    n=n/2;
                }
                else{
                    n=n/2-1;
                }
        while(arr[n]==arr[n-1]){
            n--;
        }
                g=n/3-1;

                while(arr[g]==arr[g-1]){
                    g--;
                    if(g<=0)
                        break;
                }

                s=(n-g)/2;

                 while(arr[s+g]==arr[s+g-1]){
                    s--;
                    if(s<=0)
                        break;
                }

                b=n-g-s;
        if(g<=0 || s<=0 || b<=0){
            g=0;
            s=0;
            b=0;
        }
        if(g>=s || g>=b){
            g=0;
            s=0;
            b=0;
        }
            cout<<g<<" "<<s<<" "<<b<<endl;
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long int t;
    cin>>t;
    for(long int i=0;i<t;i++){
        long int n,g,s,b;
        cin>>n;
        long int arr[n];
        for(long int j=0;j<n;j++){
            cin>>arr[j];
        }
        if(n<10){
            cout<<"0 0 0"<<endl;
        }
        else{
                if(n%2==0){
                    n=n/2;
                }
                else{
                    n=n/2-1;
                }
        while(arr[n]==arr[n-1]){
            n--;
        }
                g=n/3-1;

                while(arr[g]==arr[g-1]){
                    g--;
                    if(g<0)
                        break;
                }

                s=(n-g)/2;

                 while(arr[s+g]==arr[s+g-1]){
                    s--;
                    if(s<0)
                        break;
                }

                b=n-g-s;
        if(g<=0 || s<=0 || b<=0){
            g=0;
            s=0;
            b=0;
        }
        if(g>=s || g>=b){
            g=0;
            s=0;
            b=0;
        }
            cout<<g<<" "<<s<<" "<<b<<endl;
        }
    }
return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define pb push_back
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define flr(i,a,b) for(ll i=a;i>b;i--)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define keep_unique(v) sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
#define print(v) for(auto i=v.begin();i!=v.end();i++){cout<<*i<<" ";}cout<<"\n";
using namespace std;
int main(){
    ll t;cin>>t;
    while(t--){
        ll n,sum=0;cin>>n;
        vector<ll> v(n),vr,vrr;
        fl(i,0,n) cin>>v[i];
        ll x=n/2;ll y=v[x];
       flr(i,x-1,-1){
       if(v[i]!=y) vr.pb(v[i]);
       }
     reverse(vr.begin(),vr.end());
     x=1;
     fl(i,1,vr.size()){
     if(vr[i]==vr[i-1]) x++;
     else vrr.pb(x),x=1;
     }vrr.pb(x);
     fl(i,0,vrr.size()) sum+=vrr[i];
     if(vrr.size()<3) cout<<0<<" "<<0<<" "<<0<<endl;
     else{
          ll g=vrr[0],s=0,b=0,flag=0;
            fl(i,1,vrr.size()){
            if(s<=g) s+=vrr[i];
            else {
                flag=i;break;
            }
            }
            if(flag!=0) b=sum-g-s;
            if(s>g && b>g) cout<<g<<" "<<s<<" "<<b<<endl;
    else cout<<0<<" "<<0<<" "<<0<<endl;
     }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long int t;
    cin>>t;
    for(long int i=0;i<t;i++){
        long int n,g,s,b;
        cin>>n;
        long int arr[n];
        for(long int j=0;j<n;j++){
            cin>>arr[j];
        }
        if(n<10){
            cout<<"0 0 0"<<endl;
        }
        else{
                if(n%2==0){
                    n=n/2;
                }
                else{
                    n=n/2-1;
                }
        while(arr[n]==arr[n-1]){
            n--;
        }
                g=n/3-1;

                while(arr[g]==arr[g-1]){
                    g--;
                }

                s=(n-g)/2;

                 while(arr[s+g]==arr[s+g-1]){
                    s--;
                }

                b=n-g-s;

            cout<<g<<" "<<s<<" "<<b<<endl;
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long int t;
    cin>>t;
    for(long int i=0;i<t;i++){
        long int n,g,s,b;
        cin>>n;
        long int arr[n];
        for(long int j=0;j<n;j++){
            cin>>arr[j];
        }
        if(n<10){
            cout<<"0 0 0"<<endl;
        }
        else{
                if(n%2==0){
                    n=n/2;
                }
                else{
                    n=n/2-1;
                }
        while(arr[n]==arr[n-1]){
            n--;
        }
        if(n>4){
           g=n/3-1;

                while(arr[g]==arr[g-1]){
                    g--;
                    if(g==0)
                    {
                        break;
                    }
                }

                s=(n-g)/2;

                 while(arr[s+g]==arr[s+g-1]){
                    s--;
                    if(s==0){
                        break;
                    }
                }

                b=n-g-s;
        if(g<=0 || s<=0 || b<=0){
            g=0;
            s=0;
            b=0;
        }
        if(g>=s || g>=b){
            g=0;
            s=0;
            b=0;
        }
            cout<<g<<" "<<s<<" "<<b<<endl;
        }
            else{
                  cout<<"0 0 0"<<endl;
            }
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long int t;
    cin>>t;
    for(long int i=0;i<t;i++){
        long int n,g,s,b;
        cin>>n;
        long int arr[n];
        for(long int j=0;j<n;j++){
            cin>>arr[j];
        }
        if(n<10){
            cout<<"0 0 0"<<endl;
        }
        else{
                if(n%2==0){
                    n=n/2;
                }
                else{
                    n=n/2-1;
                }
        while(arr[n]==arr[n-1]){
            n--;
        }
                g=n/3-1;

                while(arr[g]==arr[g-1]){
                    g--;
                }

                s=(n-g)/2;

                 while(arr[s+g]==arr[s+g-1]){
                    s--;
                }

                b=n-g-s;
        if(g<0 || s<0 || b<0){
            g=0;
            s=0;
            b=0;
        }
            cout<<g<<" "<<s<<" "<<b<<endl;
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long int t;
    cin>>t;
    for(long int i=0;i<t;i++){
        long int n,g,s,b;
        cin>>n;
        long int arr[n];
        for(long int j=0;j<n;j++){
            cin>>arr[j];
        }
        if(n<10){
            cout<<"0 0 0"<<endl;
        }
        else{
                if(n%2==0){
                    n=n/2;
                }
                else{
                    n=n/2-1;
                }
        while(arr[n]==arr[n-1]){
            n--;
        }
                g=n/3-1;

                while(arr[g]==arr[g-1] && g>0){
                    g--;
                    if(g<=0)
                        break;
                }

                s=(n-g)/2;

                 while(arr[s+g]==arr[s+g-1] && s+g>0){
                    s--;
                    if(s<=0)
                        break;
                }

                b=n-g-s;
        if(g<=0 || s<=0 || b<=0){
            g=0;
            s=0;
            b=0;
        }
        if(g>=s || g>=b){
            g=0;
            s=0;
            b=0;
        }
            cout<<g<<" "<<s<<" "<<b<<endl;
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long int t;
    cin>>t;
    for(long int i=0;i<t;i++){
        long int n,g,s,b;
        cin>>n;
        long int arr[n];
        for(long int j=0;j<n;j++){
            cin>>arr[j];
        }
        if(n<10){
            cout<<"0 0 0"<<endl;
        }
        else{
                if(n%2==0){
                    n=n/2;
                }
                else{
                    n=n/2-1;
                }
        while(arr[n]==arr[n-1]){
            n--;
            if(n==0)
                break;
        }
        if(n>4){
           g=n/3-1;

                while(arr[g]==arr[g-1]){
                    g--;
                    if(g==0)
                    {
                        break;
                    }
                }

                s=(n-g)/2;

                 while(arr[s+g]==arr[s+g-1]){
                    s--;
                    if(s==0){
                        break;
                    }
                }

                b=n-g-s;
        if(g<=0 || s<=0 || b<=0){
            g=0;
            s=0;
            b=0;
        }
        if(g>=s || g>=b){
            g=0;
            s=0;
            b=0;
        }
            cout<<g<<" "<<s<<" "<<b<<endl;
        }
            else{
                  cout<<"0 0 0"<<endl;
            }
        }
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define llu unsigned long long int
#define scll(x) scanf("%lld",&x)
#define scld(x) scanf("%lf",&x)
#define scull(x) scanf("%llu",&x)
#define scch(x) scanf(" %c",&ch)
#define Pi acos(-1.0)
#define MEM(a,b) memset(a,b,sizeof(a))
ll __xor(ll a,ll b){return a^b;}
ll __and(ll a,ll b){return a&b;}
ll __or(ll a,ll b){return a|b;}
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll ai[1000],pi[1000];
int main()
{
    ll b,c=0,x,y,z,t,i,j,k,l1=0,l2,n,c1=0,c2=0,q;

               scll(t);
               while(t--)
               {
                   scll(n);
                   ll a[n];
                   map<ll,ll>m;
                   for(i=0;i<n;i++)
                    scll(a[i]);
                    if(n/2>=3)
                    {
                    if(a[(n/2)-1]!=a[(n/2)])
                    {
                      for(j=0;j<(n/2);j++)
                      {
                          if(a[j]>a[j+1]&&l1<=1){
                                c++;
                                if(l1==0){
                                    m[l1++]=c;
                                    c=0;
                                }
                                else if(l1==1&&m[l1-1]<c){
                                  m[l1++]=c;
                                 c=0;
                                }
                          }
                          else
                            c++;
                      }
                      m[l1]=c;
                    }
                    else
                    {
                        for(j=0;a[j]>a[n/2];j++)
                        {
                            if(a[j]>a[j+1]&&l1<=1){
                                    c++;
                            if(l1==1&&m[l1-1]<c){
                                  m[l1++]=c;
                             c=0;
                            }
                                  else if(l1==0){
                                    m[l1++]=c;
                                c=0;
                          }
                            }
                          else
                         c++;
                      }
                      m[l1]=c;
                        }
                        if(l1==2)
                        {
                            for(j=0;j<3;j++)
                                cout<<m[j]<<" ";
                        }
                        else
                            cout<<"0 0 0";
                    }
                    else
                        cout<<"0 0 0";
                    l1=0;
                    c=0;
                    cout<<"\n";
               }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define llu unsigned long long int
#define scll(x) scanf("%lld",&x)
#define scld(x) scanf("%lf",&x)
#define scull(x) scanf("%llu",&x)
#define scch(x) scanf(" %c",&ch)
#define Pi acos(-1.0)
#define MEM(a,b) memset(a,b,sizeof(a))
ll __xor(ll a,ll b){return a^b;}
ll __and(ll a,ll b){return a&b;}
ll __or(ll a,ll b){return a|b;}
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll ai[1000],pi[1000];
int main()
{
    ll b,c=0,x,y,z,t,i,j,k,l1=0,l2,n,c1=0,c2=0,q;

               scll(t);
               while(t--)
               {
                   scll(n);
                   ll a[n];
                   map<ll,ll>m;
                   for(i=0;i<n;i++)
                    scll(a[i]);
                    if(n/2>=3)
                    {
                    if(a[(n/2)-1]!=a[(n/2)])
                    {
                      for(j=0;j<(n/2);j++)
                      {
                          if(a[j]>a[j+1]&&l1<=1){
                                c++;
                                if(l1==0){
                                    m[l1++]=c;
                                    c=0;
                                }
                                else if(l1==1&&m[l1-1]<c){
                                  m[l1++]=c;
                                 c=0;
                                }
                          }
                          else
                            c++;
                      }
                      if(c>0){
                      m[l1]=c;
                      l1++;
                    }
                    }
                    else
                    {
                        for(j=0;a[j]>a[n/2];j++)
                        {
                            if(a[j]>a[j+1]&&l1<=1){
                                    c++;
                            if(l1==1&&m[l1-1]<c){
                                  m[l1++]=c;
                             c=0;
                            }
                                  else if(l1==0){
                                    m[l1++]=c;
                                c=0;
                          }
                            }
                          else
                         c++;
                      }
                      if(c>1){
                      m[l1]=c;
                      l1++;
                        }
                    }
                        if(l1==3&&m[0]<m[1]&&m[0]<m[2])
                        {
                            for(j=0;j<3;j++)
                                cout<<m[j]<<" ";
                        }
                        else
                            cout<<"0 0 0";
                    }
                    else
                        cout<<"0 0 0";
                    l1=0;
                    c=0;
                    cout<<"\n";
               }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define llu unsigned long long int
#define scll(x) scanf("%lld",&x)
#define scld(x) scanf("%lf",&x)
#define scull(x) scanf("%llu",&x)
#define scch(x) scanf(" %c",&ch)
#define Pi acos(-1.0)
#define MEM(a,b) memset(a,b,sizeof(a))
ll __xor(ll a,ll b){return a^b;}
ll __and(ll a,ll b){return a&b;}
ll __or(ll a,ll b){return a|b;}
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll ai[1000],pi[1000];
int main()
{
    ll b,c=0,x,y,z,t,i,j,k,l1=0,l2,n,c1=0,c2=0,q;

               scll(t);
               while(t--)
               {
                   scll(n);
                   ll a[n];
                   map<ll,ll>m;
                   for(i=0;i<n;i++)
                    scll(a[i]);
                    if(n/2>=3)
                    {
                    if(a[(n/2)-1]!=a[(n/2)])
                    {
                      for(j=0;j<(n/2);j++)
                      {
                          if(a[j]>a[j+1]&&l1<=1){
                                c++;
                         m[l1++]=c;
                         c=0;
                          }
                          else
                            c++;
                      }
                      m[l1]=c;
                    }
                    else
                    {
                        c1=a[(n/2)-1];
                        for(j=0;a[j]>a[n/2];j++)
                        {
                            if(a[j]>a[j+1]&&l1<=1){
                                    c++;
                         m[l1++]=c;
                         c=0;
                          }
                          else
                         c++;
                      }
                      m[l1]=c;
                        }
                        if(l1==2)
                        {
                            for(j=0;j<3;j++)
                                cout<<m[j]<<" ";
                        }
                        else
                            cout<<"0 0 0";
                    }
                    else
                        cout<<"0 0 0";
                    l1=0;
                    c=0;
                    cout<<"\n";
               }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define llu unsigned long long int
#define scll(x) scanf("%lld",&x)
#define scld(x) scanf("%lf",&x)
#define scull(x) scanf("%llu",&x)
#define scch(x) scanf(" %c",&ch)
#define Pi acos(-1.0)
#define MEM(a,b) memset(a,b,sizeof(a))
ll __xor(ll a,ll b){return a^b;}
ll __and(ll a,ll b){return a&b;}
ll __or(ll a,ll b){return a|b;}
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll ai[1000],pi[1000];
int main()
{
    ll b,c=0,x,y,z,t,i,j,k,l1=0,l2,n,c1=0,c2=0,q;

               scll(t);
               while(t--)
               {
                   scll(n);
                   ll a[n];
                   map<ll,ll>m;
                   for(i=0;i<n;i++)
                    scll(a[i]);
                    if(n/2>=3)
                    {
                    if(a[(n/2)-1]!=a[(n/2)])
                    {
                      for(j=0;j<(n/2);j++)
                      {
                          if(a[j]>a[j+1]&&l1<=1){
                                c++;
                                if(l1==0){
                                    m[l1++]=c;
                                    c=0;
                                }
                                else if(l1==1&&m[l1-1]<c){
                                  m[l1++]=c;
                                 c=0;
                                }
                          }
                          else
                            c++;
                      }
                      if(c>0){
                      m[l1]=c;
                      l1++;
                    }
                    }
                    else
                    {
                        for(j=0;a[j]>a[n/2];j++)
                        {
                            if(a[j]>a[j+1]&&l1<=1){
                                    c++;
                            if(l1==1&&m[l1-1]<c){
                                  m[l1++]=c;
                             c=0;
                            }
                                  else if(l1==0){
                                    m[l1++]=c;
                                c=0;
                          }
                            }
                          else
                         c++;
                      }
                      if(c>1){
                      m[l1]=c;
                      l1++;
                        }
                    }
                        if(l1==3)
                        {
                            for(j=0;j<3;j++)
                                cout<<m[j]<<" ";
                        }
                        else
                            cout<<"0 0 0";
                    }
                    else
                        cout<<"0 0 0";
                    l1=0;
                    c=0;
                    cout<<"\n";
               }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define llu unsigned long long int
#define scll(x) scanf("%lld",&x)
#define scld(x) scanf("%lf",&x)
#define scull(x) scanf("%llu",&x)
#define scch(x) scanf(" %c",&ch)
#define Pi acos(-1.0)
#define MEM(a,b) memset(a,b,sizeof(a))
ll __xor(ll a,ll b){return a^b;}
ll __and(ll a,ll b){return a&b;}
ll __or(ll a,ll b){return a|b;}
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll ai[1000],pi[1000];
int main()
{
    ll b,c=0,x,y,z,t,i,j,k,l1=0,l2,n,c1=0,c2=0,q;

               scll(t);
               while(t--)
               {
                   scll(n);
                   ll a[n];
                   map<ll,ll>m;
                   for(i=0;i<n;i++)
                    scll(a[i]);
                    if(n/2>=3)
                    {
                    if(a[(n/2)-1]!=a[(n/2)])
                    {
                      for(j=0;j<(n/2);j++)
                      {
                          if(a[j]>a[j+1]&&l1<=1){
                                c++;
                                if(l1==0){
                                    m[l1++]=c;
                                    c=0;
                                }
                                else if(l1==1&&m[l1-1]<c){
                                  m[l1++]=c;
                                 c=0;
                                }
                          }
                          else
                            c++;
                      }
                      m[l1]=c;
                      l1++;
                    }
                    else
                    {
                        for(j=0;a[j]>a[n/2];j++)
                        {
                            if(a[j]>a[j+1]&&l1<=1){
                                    c++;
                            if(l1==1&&m[l1-1]<c){
                                  m[l1++]=c;
                             c=0;
                            }
                                  else if(l1==0){
                                    m[l1++]=c;
                                c=0;
                          }
                            }
                          else
                         c++;
                      }
                      if(a[j]!=a[n/2]){
                      m[l1]=c;
                      l1++;
                        }
                    }
                        if(l1==3)
                        {
                            for(j=0;j<3;j++)
                                cout<<m[j]<<" ";
                        }
                        else
                            cout<<"0 0 0";
                    }
                    else
                        cout<<"0 0 0";
                    l1=0;
                    c=0;
                    cout<<"\n";
               }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
int main() {
	ios::sync_with_stdio(false);
	int T; cin>>T;
	while (T--) {
		cin>>n;
		for (int i=1; i<=n; i++) cin>>a[i];
		int half = n>>1, las = a[half+1];
		while (a[half]==las) half--;
		int diff=0,p[100005],me[4]={0};
		for (int i=1; i<=half; i++)
			if (a[i]!=a[i-1]) p[diff++]=i;
		if (diff<2) cout<<"0 0 0";
		else {
			me[1]=p[1]-1; int y=0;
			// silver
			for (int i=2; i<=diff; i++) {
				me[2]+=p[i]-p[i-1];
				if (me[2]>me[1]) {y=i;break;}
			}
			me[3]=half-me[1]-me[2];
			if (me[3]>me[1])
				for (int i=1; i<=3; i++) cout<<me[i]<<" ";
			else cout<<"0 0 0";
		}
		cout<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
int main() {
	ios::sync_with_stdio(false);
	int T; cin>>T;
	while (T--) {
		cin>>n;
		for (int i=1; i<=n; i++) cin>>a[i];
		int half = n>>1, las = a[half+1];
		while (a[half]==las) half--;
		int diff=0,p[100005],me[4]={0};
		for (int i=1; i<=half; i++)
			if (a[i]!=a[i-1]) p[diff++]=i;
		if (diff<2) cout<<"0 0 0";
		else {
			me[1]=p[1]-1;
			// silver
			for (int i=2; i<=diff; i++) {
				me[2]+=p[i]-p[i-1];
				if (me[2]>me[1]) break;
			}
			if (me[2]<=me[1]) cout<<"0 0 0";
			else {
				me[3]=half-me[1]-me[2];
				if (me[3]>me[1]) for (int i=1; i<=3; i++) cout<<me[i]<<" ";
				else cout<<"0 0 0";
			}
		}
		cout<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
int n,a[400005];
int main() {
	ios::sync_with_stdio(false);
	int T; cin>>T;
	while (T--) {
		cin>>n;
		for (int i=1; i<=n; i++) cin>>a[i];
		int half = n/2, las = a[half+1];
		while (a[half]==las) half--;
		int diff=0,p[200005],me[4]={0};
		for (int i=1; i<=half; i++)
			if (a[i]!=a[i-1]) p[diff++]=i;
		if (diff<2) cout<<"0 0 0";
		else {
			me[1]=p[1]-1;
			// silver
			for (int i=2; i<diff; i++) {
				me[2]+=p[i]-p[i-1];
				if (me[2]>me[1]) break;
			}
			if (me[2]<=me[1]) cout<<"0 0 0";
			else {
				me[3]=half-me[1]-me[2];
				if (me[3]>me[1]) for (int i=1; i<=3; i++) cout<<me[i]<<" ";
				else cout<<"0 0 0";
			}
		}
		cout<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
int main() {
	ios::sync_with_stdio(false);
	int T; cin>>T;
	while (T--) {
		cin>>n;
		for (int i=1; i<=n; i++) cin>>a[i];
		int half = n>>1, las = a[half+1];
		while (a[half]==las) half--;
		int diff=0,p[100005],me[4]={0};
		for (int i=1; i<=half; i++)
			if (a[i]!=a[i-1]) p[diff++]=i;
		if (diff<2) {
			cout<<"0 0 0\n";
			continue;
		}
		else {
			me[1]=p[1]-1; int y=0;
			// silver
			for (int i=2; i<=diff; i++) {
				me[2]+=p[i]-p[i-1];
				if (me[2]>me[1]) {y=i;break;}
			}
			me[3]=half-me[1]-me[2];
			if (me[3]>me[1])
				for (int i=1; i<=3; i++) cout<<me[i]<<" ";
			else cout<<"0 0 0";
			puts("");
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
int n,a[400005];
int main() {
	ios::sync_with_stdio(false);
	int T; cin>>T;
	while (T--) {
		cin>>n;
		for (int i=1; i<=n; i++) cin>>a[i];
		int half = n>>1, las = a[half+1];
		while (a[half]==las) half--;
		int diff=0,p[200005],me[4]={0};
		for (int i=1; i<=half; i++)
			if (a[i]!=a[i-1]) p[diff++]=i;
		if (diff<2) cout<<"0 0 0";
		else {
			me[1]=p[1]-1;
			// silver
			for (int i=2; i<=diff; i++) {
				me[2]+=p[i]-p[i-1];
				if (me[2]>me[1]) break;
			}
			if (me[2]<=me[1]) cout<<"0 0 0";
			else {
				me[3]=half-me[1]-me[2];
				if (me[3]>me[1]) for (int i=1; i<=3; i++) cout<<me[i]<<" ";
				else cout<<"0 0 0";
			}
		}
		cout<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
long long n,t,x;
struct node {
	long long s;
	long long b;
}a[1000001];
bool cmp(node p,node q)
{
	return p.b<q.b;
}
map<long long ,long long>m;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		m.clear();
		int k=0;
		for(int i=1;i<=n;i++)
		{
			cin>>x;
			if(m[x]==0)
			{
				k++;
				a[k].b=x;
			}
			m[x]++;
		}
		for(int i=1;i<=k;i++)
		{
			a[i].s=m[a[i].b];
		}
		sort(a+1,a+1+k,cmp);
		long long sum=0,j=1;
		while(sum*2<n&&j<=k)
		{
			sum+=a[j].s;
			j++;
		}
		long long s1=0,s2=0,s3=0;
		long long g=n-sum;
		long long p=k-1;
		s1=a[k].s;
		while(s2<=s1)
		{
			s2+=a[p].s;
			p--;
		}
		s3=g-s1-s2;
		if(s1<=0||s2<=0||s3<=0)
		cout<<0<<" "<<0<<" "<<0<<endl;
		else
		cout<<s1<<" "<<s2<<" "<<s3<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
long long n,t,x;
struct node {
	long long s;
	long long b;
}a[1000001];
bool cmp(node p,node q)
{
	return p.b<q.b;
}
map<long long ,long long>m;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		m.clear();
		int k=0;
		for(int i=1;i<=n;i++)
		{
			cin>>x;
			if(m[x]==0)
			{
				k++;
				a[k].b=x;
			}
			m[x]++;
		}
		for(int i=1;i<=k;i++)
		{
			a[i].s=m[a[i].b];
		}
		sort(a+1,a+1+k,cmp);
		long long sum=0,j=0;
		while(sum*2<n)
		{
			j++;
			sum+=a[j].s;
		}
		long long p=j;
		long long s1=0,s2=0,s3=0;
		long long g=n-sum;
		j=k;
		while((s1+a[j].s)*3+1<g&&j>p)
		{
			s1+=a[j].s;
			j--;
		}
		g-=s1;
		while((s2+a[j].s)*2<=g&&j>p)
		{
			s2+=a[j].s;
			j--;
		}
		s3=g-s2;
		if(s1<=0||s2<=0||s3<=0)
		cout<<0<<" "<<0<<" "<<0<<endl;
		else
		cout<<s1<<" "<<s2<<" "<<s3<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
long long n,t,x;
struct node {
	long long s;
	long long b;
}a[1000001];
bool cmp(node p,node q)
{
	return p.b<q.b;
}
map<long long ,long long>m;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		m.clear();
		int k=0;
		for(int i=1;i<=n;i++)
		{
			cin>>x;
			if(m[x]==0)
			{
				k++;
				a[k].b=x;
			}
			m[x]++;
		}
		for(int i=1;i<=k;i++)
		{
			a[i].s=m[a[i].b];
		}
		sort(a+1,a+1+k,cmp);
		long long sum=0,j=1;
		while(sum*2<n&&j<=k)
		{
			sum+=a[j].s;
			j++;
		}
		long long s1=0,s2=0,s3=0;
		long long g=n-sum;
		while(s3*4<g&&j<=k)
		{
			s3+=a[j].s;
			j++;
		}
		g=g-s3;
		while(s2*2<=g||(g-s2)>=s3&&j<=k)
		{
			s2+=a[j].s;
			j++;
		}
		s1=g-s2;
		if(s1<=0||s2<=0||s3<=0)
		cout<<0<<" "<<0<<" "<<0<<endl;
		else
		cout<<s1<<" "<<s2<<" "<<s3<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
long long n,t,x;
struct node {
	long long s;
	long long b;
}a[1000001];
bool cmp(node p,node q)
{
	return p.b<q.b;
}
map<long long ,long long>m;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		m.clear();
		int k=0;
		for(int i=1;i<=n;i++)
		{
			cin>>x;
			if(m[x]==0)
			{
				k++;
				a[k].b=x;
			}
			m[x]++;
		}
		for(int i=1;i<=k;i++)
		{
			a[i].s=m[a[i].b];
		}
		sort(a+1,a+1+n,cmp);
		long long sum=0,j=1;
		while(sum*2<n)
		{
			sum+=a[j].s;
			j++;
		}
		long long s1=0,s2=0,s3=0;
		long long g=n-sum;
		while(s3*4<g)
		{
			s3+=a[j].s;
			j++;
		}
		g=g-s3;
		while(s2*2<=g||(g-s2)>=s3)
		{
			s2+=a[j].s;
			j++;
		}
		s1=g-s2;
		if(s1<=0||s2<=0||s3<=0)
		cout<<0<<" "<<0<<" "<<0<<endl;
		else
		cout<<s1<<" "<<s2<<" "<<s3<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
long long n,t,x;
struct node {
	long long s;
	long long b;
}a[1000001];
bool cmp(node p,node q)
{
	return p.b<q.b;
}
map<long long ,long long>m;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		m.clear();
		int k=0;
		for(int i=1;i<=n;i++)
		{
			cin>>x;
			if(m[x]==0)
			{
				k++;
				a[k].b=x;
			}
			m[x]++;
		}
		for(int i=1;i<=k;i++)
		{
			a[i].s=m[a[i].b];
		}
		sort(a+1,a+1+k,cmp);
		long long sum=0,j=1;
		while(sum*2<n&&j<=k)
		{
			sum+=a[j].s;
			j++;
		}
		long long s1=0,s2=0,s3=0;
		long long g=n-sum;
		long long p=k-1;
		s1=a[k].s;
		while(s2<=s1)
		{
			s2+=a[p].s;
			p--;
		}
		s3=g-s1-s2;
		if(s1<=0||s2<=0||s3<=0||(s3<=s1))
		cout<<0<<" "<<0<<" "<<0<<endl;
		else
		cout<<s1<<" "<<s2<<" "<<s3<<endl;
	}
}


#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
const int maxn = 400005;
int sorce[maxn];
int main()
{
    int cases,m;
    int ans[3];
    cin >> cases;
    while (cases--) {
        int n;
        cin >> n;
        map<int,int>mp;
        for(int i=0;i<3;i++) ans[i] = 0;

        for (int i=0 ;i<n; i++) {
            cin >> m;
            if (mp[m]) mp[m] ++;
            else mp[m] = 1;
        }

        if (mp.size() < 3) {
            cout << "0 0 0" << endl;
            continue;
        }

        map<int,int>::iterator pos = mp.end();
        pos --;
        int sum = 0;
        for (;;pos--) {
            if (sum + pos->second > n/2) {
                break;
            }
            //cout << "AAAA " << sum << " " << n/2 << endl;
            sum += pos->second;
            if (ans[0] == 0) {
                ans[0] += pos->second;
            } else if (ans[1] <= ans[0]) {
                ans[1] += pos->second;
            } else if (ans[2] <= ans[0]){
                ans[2] += pos->second;
            }
        }

        int flag = 1;
        for (int i=0;i<3;i++) {
            if (ans[i] == 0) {
                flag = 0;
                cout << "0 0 0" << endl;
                break;
            }
        }

        if (flag & 1) {
            cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
        }
    }
    return 0;
}


#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
const int maxn = 400005;
int sorce[maxn];
int main()
{
    int cases,m;
    int ans[3];
    cin >> cases;
    while (cases--) {
        int n;
        cin >> n;
        map<int,int>mp;
        for(int i=0;i<3;i++) ans[i] = 0;

        for (int i=0 ;i<n; i++) {
            cin >> m;
            if (mp[m]) mp[m] ++;
            else mp[m] = 1;
        }

        if (mp.size() < 3) {
            cout << "0 0 0" << endl;
            continue;
        }

        map<int,int>::iterator pos = mp.end();
        pos --;
        int sum = 0;
        for (;;pos--) {
            if (sum + pos->second > n/2) {
                break;
            }
            //cout << "AAAA " << sum << " " << n/2 << endl;
            sum += pos->second;
            if (ans[0] == 0) {
                ans[0] += pos->second;
                continue;
            }

            if (ans[1] <= ans[0]) {
                ans[1] += pos->second;
                continue;
            }

            ans[2] += pos->second;
        }

        int flag = 1;
        for (int i=0;i<3;i++) {
            if (ans[i] == 0) {
                flag = 0;
                cout << "0 0 0" << endl;
                break;
            }
        }

        if (ans[1] <= ans[0] || ans[2] <= ans[0]) {
            cout << "0 0 0" << endl;
            continue;
        }

        if (flag & 1) {
            cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
        }
    }
    return 0;
}


#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
const int maxn = 400005;
int sorce[maxn];
int main()
{
    int cases,m;
    int ans[3];
    cin >> cases;
    while (cases--) {
        int n;
        cin >> n;
        map<int,int>mp;
        for(int i=0;i<3;i++) ans[i] = 0;

        for (int i=0 ;i<n; i++) {
            cin >> m;
            if (mp[m]) mp[m] ++;
            else mp[m] = 1;
        }

        if (mp.size() < 3) {
            cout << "0 0 0" << endl;
            continue;
        }

        map<int,int>::iterator pos = mp.end();
        pos --;
        int sum = 0;
        for (;;pos--) {
            if (sum + pos->second > n/2) {
                break;
            }
            //cout << "AAAA " << sum << " " << n/2 << endl;
            sum += pos->second;
            if (ans[0] == 0) {
                ans[0] += pos->second;
                continue;
            }

            if (ans[1] <= ans[0]) {
                ans[1] += pos->second;
                continue;
            }

            ans[2] += pos->second;
        }

        int flag = 1;
        for (int i=0;i<3;i++) {
            if (ans[i] == 0) {
                flag = 0;
                cout << "0 0 0" << endl;
                break;
            }
        }

        if (flag== 0 && (ans[1] <= ans[0] || ans[2] <= ans[0])) {
            cout << "0 0 0" << endl;
            continue;
        }

        if (flag & 1) {
            cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
        }
    }
    return 0;
}


#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
const int maxn = 400005;
int sorce[maxn];
int main()
{
    int cases,m;
    int ans[3];
    cin >> cases;
    while (cases--) {
        int n;
        cin >> n;
        map<int,int>mp;
        for(int i=0;i<3;i++) ans[i] = 0;

        for (int i=0 ;i<n; i++) {
            cin >> m;
            if (mp[m]) mp[m] ++;
            else mp[m] = 1;
        }

        if (mp.size() < 3) {
            cout << "0 0 0" << endl;
            continue;
        }

        map<int,int>::iterator pos = mp.end();
        pos --;
        int sum = 0;
        for (;;pos--) {
            if (sum + pos->second > n/2) {
                break;
            }
            //cout << "AAAA " << sum << " " << n/2 << endl;
            sum += pos->second;
            if (ans[0] == 0) {
                ans[0] += pos->second;
            } else if (ans[1] <= ans[0]) {
                ans[1] += pos->second;
            } else {
                ans[2] += pos->second;
            }
        }

        int flag = 1;
        for (int i=0;i<3;i++) {
            if (ans[i] == 0) {
                flag = 0;
                cout << "0 0 0" << endl;
                break;
            }
        }

        if (flag & 1) {
            cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
        }
    }
    return 0;
}


#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
const int maxn = 400005;
int sorce[maxn];
int main()
{
    int cases,m;
    int ans[3];
    cin >> cases;
    while (cases--) {
        int n;
        cin >> n;
        map<int,int>mp;
        for(int i=0;i<3;i++) ans[i] = 0;

        for (int i=0 ;i<n; i++) {
            cin >> m;
            if (mp[m]) mp[m] ++;
            else mp[m] = 1;
        }

        if (mp.size() < 3) {
            cout << "0 0 0" << endl;
            continue;
        }

        map<int,int>::iterator pos = mp.end();
        pos --;
        int sum = 0;
        for (;;pos--) {
            if (sum + pos->second > n/2) {
                break;
            }
            //cout << "AAAA " << sum << " " << n/2 << endl;
            sum += pos->second;
            if (ans[0] == 0) {
                ans[0] += pos->second;
                continue;
            }

            if (ans[1] <= ans[0]) {
                ans[1] += pos->second;
                continue;
            }

            ans[2] += pos->second;
        }

        int flag = 1;
        for (int i=0;i<3;i++) {
            if (ans[i] == 0) {
                flag = 0;
                cout << "0 0 0" << endl;
                break;
            }
        }

        if (flag == 1 && (ans[1] <= ans[0] || ans[2] <= ans[0])) {
            cout << "0 0 0" << endl;
            continue;
        }

        if (flag & 1) {
            cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
        }
    }
    return 0;
}


#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
const int maxn = 400005;
int sorce[maxn];
int main()
{
    int cases,m;
    int ans[3];
    cin >> cases;
    while (cases--) {
        int n;
        cin >> n;
        map<int,int>mp;
        for(int i=0;i<3;i++) ans[i] = 0;

        for (int i=0 ;i<n; i++) {
            cin >> m;
            if (mp[m]) mp[m] ++;
            else mp[m] = 1;
        }

        if (mp.size() < 3) {
            cout << "0 0 0" << endl;
            continue;
        }

        map<int,int>::iterator pos = mp.end();
        pos --;
        int sum = 0;
        for (;;pos--) {
            if (sum + pos->second > n/2) {
                break;
            }
            //cout << "AAAA " << sum << " " << n/2 << endl;
            sum += pos->second;
            if (ans[0] == 0) {
                ans[0] += pos->second;
            } else if (ans[1] == 0) {
                ans[1] += pos->second;
            } else {
                ans[2] += pos->second;
            }
        }

        int flag = 1;
        for (int i=0;i<3;i++) {
            if (ans[i] == 0) {
                flag = 0;
                cout << "0 0 0" << endl;
                break;
            }
        }

        if (flag & 1) {
            cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
        }
    }
    return 0;
}


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

#define sc scanf
#define ls rt << 1
#define rs ls | 1
#define Min(x, y) x = min(x, y)
#define Max(x, y) x = max(x, y)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define MEM(x, b) memset(x, b, sizeof(x))
#define lowbit(x) ((x) & -(x))
#define P2(x) ((x) * (x))

typedef long long ll;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 100;
const int INF = 0x3f3f3f3f;
inline ll fpow(ll a, ll b){ ll r = 1, t = a; while (b){ if (b & 1)r = (r*t) % MOD; b >>= 1; t = (t*t) % MOD; }return r; }

vector <int> e;
int p[MAXN], n;

int main()
{
	int T; cin >> T;
	while (T--) {
		sc("%d", &n); e.clear();
		for (int i = 1; i <= n; i++) sc("%d", &p[i]);
		for (int i = 1; i < n; i++) {
			if (p[i] > p[i + 1]) e.push_back(i);
		}
		int sz = SZ(e), tot = n / 2;
		if (sz == 0 || sz == 1) { printf("0 0 0\n"); continue; }
		int g = e[0];
		int j = upper_bound(ALL(e), 2 * g) - e.begin();
		if (j == sz) { printf("0 0 0\n"); continue; }
		int s = e[j] - g, b;
		int k = upper_bound(ALL(e), tot) - e.begin();
		b = e[k - 1] - e[j];
		if (g < s && g < b && g + s + b <= tot) printf("%d %d %d\n", g, s, b);
		else printf("0 0 0\n");
	}
	return 0;  // 改数组大小!!!
}


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

#define sc scanf
#define ls rt << 1
#define rs ls | 1
#define Min(x, y) x = min(x, y)
#define Max(x, y) x = max(x, y)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define MEM(x, b) memset(x, b, sizeof(x))
#define lowbit(x) ((x) & -(x))
#define P2(x) ((x) * (x))

typedef long long ll;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 100;
const int INF = 0x3f3f3f3f;
inline ll fpow(ll a, ll b){ ll r = 1, t = a; while (b){ if (b & 1)r = (r*t) % MOD; b >>= 1; t = (t*t) % MOD; }return r; }

int p[MAXN], n, sum, g, s, b;
int w[MAXN];

int main()
{
	int T; cin >> T;
	while (T--) {
		sc("%d", &n); s = b = g = 1; MEM(w, 0);
		for (int i = 1; i <= n; i++) sc("%d", &p[i]);
		int cnt = p[1], j = 1;
		int tot = n / 2;
		for (int i = 2; i <= n; i++) {
			if (p[i] == cnt) g++;
			else { j = i; break; }
		}
		int scnt = p[j], k = 1;
		for (int i = j + 1; i <= n; i++) {
			if (p[i] == scnt) s++;
			else {
				if (s <= g) scnt = p[i], s++;
				else { k = i; break; }
			}
		}
		int stot = p[k], X = 0;
		for (int i = k + 1; i <= n; i++) {
			if (p[i] == stot) b++;
			else {
				w[++X] = b;
				if (g + s + b > tot) { b = w[X - 1]; break; }
				else if (g + s + b == tot) break;
				else stot = p[i], b++;
			}
		}
		if (g < s && g < b && g + s + b <= tot && g && s && b) printf("%d %d %d\n", g, s, b);
		else printf("0 0 0\n");
	}
	return 0;  // 改数组大小!!!
}


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

#define sc scanf
#define ls rt << 1
#define rs ls | 1
#define Min(x, y) x = min(x, y)
#define Max(x, y) x = max(x, y)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define MEM(x, b) memset(x, b, sizeof(x))
#define lowbit(x) ((x) & -(x))
#define P2(x) ((x) * (x))

typedef long long ll;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 100;
const int INF = 0x3f3f3f3f;
inline ll fpow(ll a, ll b){ ll r = 1, t = a; while (b){ if (b & 1)r = (r*t) % MOD; b >>= 1; t = (t*t) % MOD; }return r; }

int p[MAXN], n, sum, g, s, b;
int w[MAXN];

int main()
{
	int T; cin >> T;
	while (T--) {
		sc("%d", &n); s = b = g = 1; MEM(w, 0);
		for (int i = 1; i <= n; i++) sc("%d", &p[i]);
		int cnt = p[1], j = 1;
		int tot = n / 2;
		for (int i = 2; i <= n; i++) {
			if (p[i] == cnt) g++;
			else { j = i; break; }
		}
		int scnt = p[j], k;
		for (int i = j + 1; i <= n; i++) {
			if (p[i] == scnt) s++;
			else {
				if (s <= g) scnt = p[i], s++;
				else { k = i; break; }
			}
		}
		if (s <= g) { cout << "0 0 0" << endl; continue; }
		int stot = p[k], X = 0;
		for (int i = k + 1; i <= n; i++) {
			if (p[i] == stot) b++;
			else {
				w[++X] = b;
				if (g + s + b > tot) { b = w[X - 1]; break; }
				else if (g + s + b == tot) break;
				else stot = p[i], b++;
			}
		}
		if (g < s && g < b && g + s + b <= tot) printf("%d %d %d\n", g, s, b);
		else printf("0 0 0\n");
	}
	return 0;  // 改数组大小!!!
}