#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#define _CRT_NO_DEPRECEATE
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <memory.h>
#include <sstream>
#include <cassert>
#include <ctime>

#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define mp make_pair
#define sq(x) ((x)*(x))
#define tmin(x,y,z) (min(min((x),(y)),(z)))
#define _MOD 1000000007LL
#define MOD(x) ((x) % (_MOD))
#define NMOD(x) (((x) + 2LL * (_MOD)) % (_MOD))
#define INF (2e9)
#define LINF (1e16)
#define EPS (1e-8)
#define PI (3.1415926535897932384626433832795)
#define y1 asdf_1
#define y0 asdf_2
#define j0 jj0
typedef unsigned long long ull;
typedef long double ldd;

using namespace std;

int m, k;
int a[100010];
int t[100010];
int r[100010];
int yes[100010];
int willbe[100010];
int timer = 0;

void solve()
{
    timer++;
    cin >> m >> k;
    for (int i = 0; i < k; i++)
        cin >> a[i];

    for (int i = 0; i < m - 1; i++)
        cin >> t[i] >> r[i];

    int was_upset = -1;
    for (int i = 0; i < m - 1; i++)
        if (r[i] == 1)
        {
            was_upset = i;
            break;
        }
    if(was_upset != -1)
        for (int i = m - 2; i >= was_upset; i--)
            if (t[i] != 0)
                willbe[t[i] - 1] = timer;

    int unk = 0;
    for (int i = 0; i < m - 1; i++)
    {
        if (i == was_upset)
        {
            int mn = -1;
            for (int j = 0; j < k; j++)
                if ((willbe[j] != timer) && (a[j] <= unk))
                {
                    yes[j] = timer;
                    if (mn == -1 || a[j] < mn)
                        mn = a[j];
                }
            unk -= mn;
        }

        if (t[i] == 0)
            unk++;
        else
            a[t[i] - 1]--;
    }
    for (int i = 0; i < k; i++)
    {
        if (yes[i] == timer || a[i] <= unk)
            cout << 'Y';
        else
            cout << 'N';
    }
}

int main()
{
    //freopen("input.txt", "w", stdout); testgen(200000); return 0;

    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    int ts;
    cin >> ts;
    for (int tt = 0; tt < ts; tt++)
    {
        solve();
        cout << endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
	int t, m, k, minn, sec;
	bool ok, bb;
	vector <int> a(100100), x(100100), y(100100);
	vector <bool> b(100100), used(100100);
	scanf("%d", &t);
	for(int z=0; z<t; z++){
		scanf("%d%d", &m, &k);
		minn = 100100;
		ok = false;
		bb = false;
		sec = 0;
		for(int i=1; i<=k; i++){
			b[i] = false;
			used[i] = false;
			scanf("%d", &a[i]);
		}

		for(int i=1; i<m; i++){
			scanf("%d%d", &x[i], &y[i]);
			if(y[i] == 1) bb = true;
			if(bb) used[x[i]] = true;
		}
		for(int i=1; i<=k; i++){
			if(!used[i] && a[i] < minn) minn = a[i];
		}
		for(int i=1; i<m; i++){
			if(!ok && y[i] == 1){
				ok = true;
				for(int j=1; j<=k; j++){
					if(a[j] <= sec && !used[j]) b[j] = true;
				}
				sec -= minn;
			}
			if(x[i] == 0) sec++;
			else {
				a[x[i]]--;
				if(!used[x[i]] && a[x[i]] < minn) minn = a[x[i]];
			}
		}

		for(int i=1; i<=k; i++){
			if(b[i] || a[i] <= sec) printf("Y");
			else printf("N");
		}
		printf("\n");

	}

	return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
	int t, m, k, minn, x, y, sec;
	bool ok;
	vector <int> a(100100);
	vector <bool> b(100100);
	scanf("%d", &t);
	for(int z=0; z<t; z++){
		scanf("%d%d", &m, &k);
		minn = 100100;
		ok = false;
		sec = 0;
		for(int i=1; i<=k; i++){
			b[i] = false;
			scanf("%d", &a[i]);
			if(a[i] < minn) minn = a[i];
		}

		for(int i=1; i<m; i++){
			scanf("%d%d", &x, &y);
			if(!ok && y == 1){
				ok = true;
				for(int j=1; j<=k; j++){
					if(a[j] <= sec) b[j] = true;
				}
				sec -= minn;
			}
			if(x == 0) sec++;
			else {
				a[x]--;
				if(a[x] < minn) minn = a[x];
			}
		}

		for(int i=1; i<=k; i++){
			if(b[i] || a[i] <= sec) printf("Y");
			else printf("N");
		}
		printf("\n");

	}

	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#include <functional>
#include <time.h>
#include <cmath>
#include <deque>

using namespace std;

#define lli long long
#define mp make_pair
#define pb push_back
#define double long double
#define pii pair<int, int>

lli EPS = 1000000007;
double PI = 3.14159265358979323846;
const int MAXN = 1000010;

lli n, m, k, r, t;

int a[MAXN];
pii b[MAXN];
int c[MAXN];
bool bf[MAXN];
int index = 0;
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &t);
    for (int q = 0; q < t; q++)
    {
        scanf("%d %d", &m, &k);
        for (int i = 1; i <= k; i++)
        {
            scanf("%d", &a[i]);
        }
        for (int i = 1; i < m; i++)
        {
            scanf("%d %d", &b[i].first, &b[i].second);
            if (b[i].first > 0)
            {
                c[b[i].first] = i;
            }
        }
        int count = 0;
        int res = 0;
        for (int i = 1; i < m; i++)
        {
            if (b[i].second == 1 && res == 0)
            {
                int y = EPS;
                int w = 0;
                for (int j = 1; j <= k; j++)
                {
                    if (c[j] < i && a[j] < y)
                    {
                        y = a[j];
                        w = j;
                    }
                    if (c[j] < i && a[j] <= count)
                    {
                        a[j] = 0;
                    }
                }
                a[w] = 0;
                count -= y;
                res = 1;
                a[b[i].first]--;
                if (b[i].first == 0)
                {
                    count++;
                }
                continue;
            }
            if (b[i].first == 0)
            {
                count++;
                continue;
            }
            a[b[i].first]--;
            if (a[b[i].first] == 0)
            {
                res = 1;
            }
        }
        for (int i = 1; i <= k; i++)
        {
            if (a[i] - count <= 0)
            {
                printf("Y");
            }
            else
            {
                printf("N");
            }
        }
        printf("\n");
    }
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#include <functional>
#include <time.h>
#include <cmath>
#include <deque>

using namespace std;

#define lli long long
#define mp make_pair
#define pb push_back
#define double long double
#define pii pair<int, int>

lli EPS = 1000000007;
double PI = 3.14159265358979323846;
const int MAXN = 1000010;

lli n, m, k, r, t;

int a[MAXN];
pii b[MAXN];
int c[MAXN];
bool bf[MAXN];
int index = 0;
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &t);
    for (int q = 0; q < t; q++)
    {
        scanf("%d %d", &m, &k);
        for (int i = 1; i <= k; i++)
        {
            scanf("%d", &a[i]);
        }
        for (int i = 1; i < m; i++)
        {
            scanf("%d %d", &b[i].first, &b[i].second);
            if (b[i].first > 0)
            {
                c[b[i].first] = i;
            }
        }
        int count = 0;
        int res = 0;
        for (int i = 1; i < m; i++)
        {
            if (b[i].second == 1 && res == 0)
            {
                int y = EPS;
                int w = 0;
                for (int j = 1; j <= k; j++)
                {
                    if (c[j] < i && a[j] < y)
                    {
                        y = a[j];
                        w = j;
                    }
                    if (c[j] < i && a[j] <= count)
                    {
                        a[j] = 0;
                    }
                }
                a[w] = 0;
                count -= y;
                res = 1;
                a[b[i].first]--;
                if (b[i].first == 0)
                {
                    count++;
                }
                continue;
            }
            if (b[i].first == 0)
            {
                count++;
                continue;
            }
            a[b[i].first]--;
            if (a[b[i].first] == 0)
            {
                res = 1;
            }
        }
        for (int i = 1; i <= k; i++)
        {
            if (a[i] - count <= 0)
            {
                printf("Y");
            }
            else
            {
                printf("N");
            }
        }
        printf("\n");
        for (int i = 0; i <= k; i++)
        {
            a[i] = 0;
            c[i] = 0;
        }
        for (int i = 0; i <= m; i++)
        {
            b[i].first = 0;
            b[i].second = 0;
            c[i] = 0;
        }
    }
    return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#include <cstring>
#include <cmath>

#define mp make_pair
#define ZERO(x) memset((x), 0, sizeof(x))
#define NEGATE(x) memset((x), 255, sizeof(x))
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

// globals starts here
const int MAX_K = 100050;

int a[MAX_K];
bool e[MAX_K];
bool rest[MAX_K];
int tt[MAX_K];

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

    ios_base::sync_with_stdio(false);

    int tests;
    cin >> tests;

    for (int tc = 0; tc < tests; ++tc)
    {
        int m, k;
        cin >> m >> k;
        ZERO(e);
        ZERO(rest);

        for (int i = 0; i < k; ++i)
        {
            cin >> a[i];
        }

        int disapp_index = -1;
        for (int i = 0; i < m - 1; ++i)
        {
            int r;
            cin >> tt[i] >> r;

            if (r == 1 && disapp_index == -1)
            {
                disapp_index = i;
            }

            if (disapp_index != -1 && tt[i] > 0)
            {
                rest[tt[i] - 1] = true;
            }
        }

        int unknown = 0;
        for (int i = 0; i < m - 1; ++i)
        {
            int t = tt[i];

            if (i == disapp_index)
            {
                int mi = INT_MAX;
                for (int j = 0; j < k; ++j)
                {
                    if (!rest[j] && mi > a[j])
                    {
                        mi = a[j];
                    }

                    if (!rest[j] && a[j] - unknown <= 0)
                    {
                        e[j] = true;
                    }
                }
                unknown -= mi;
            }

            if (t == 0)
            {
                ++unknown;
            }
            else
            {
                --a[t - 1];
            }
        }

        for (int j = 0; j < k; ++j)
        {
            if (e[j] || a[j] - unknown <= 0)
            {
                cout << "Y";
            }
            else
            {
                cout << "N";
            }
        }
        cout << endl;
    }

    return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#include <cstring>
#include <cmath>

#define mp make_pair
#define ZERO(x) memset((x), 0, sizeof(x))
#define NEGATE(x) memset((x), 255, sizeof(x))
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

// globals starts here
const int MAX_K = 100050;

int a[MAX_K];
bool e[MAX_K];

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

    ios_base::sync_with_stdio(false);

    int tests;
    cin >> tests;

    for (int tc = 0; tc < tests; ++tc)
    {
        int m, k;
        cin >> m >> k;
        ZERO(e);

        for (int i = 0; i < k; ++i)
        {
            cin >> a[i];
        }

        bool disapp = false;
        int unknown = 0;
        for (int i = 0; i < m - 1; ++i)
        {
            int t, r;
            cin >> t >> r;

            if (r == 1 && !disapp)
            {
                int mi = INT_MAX;
                for (int j = 0; j < k; ++j)
                {
                    mi = min(mi, a[j]);
                    if (a[j] - unknown <= 0)
                    {
                        e[j] = true;
                    }
                }
                unknown -= mi;
                disapp = true;
            }

            if (t == 0)
            {
                ++unknown;
            }
            else
            {
                --a[t - 1];
            }
        }

        for (int j = 0; j < k; ++j)
        {
            if (e[j] || a[j] - unknown <= 0)
            {
                cout << "Y";
            }
            else
            {
                cout << "N";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#include <unordered_set>
#include <unordered_map>

#include <vector>
#include <list>

#include <set>
#include <map>

#include <string>
#include <vector>
#include <queue>

#include <algorithm>

typedef uint8_t u8;
typedef int8_t i8;

typedef uint32_t u32;
typedef int32_t i32;

typedef uint64_t u64;
typedef int64_t i64;

#define sqr(x) x*x

#define INF 100002

using namespace std;

struct less_key
{
    bool operator() (const pair<u32, u32>& p1, const pair<u32, u32>& p2)
    {
        return p1.first < p2.first || (p1.first == p2.first && p1.second < p2.second);
    }
};

u32 t;

u32 a[100002];
pair<u32, u32> A[100002];

u32 r[100002];
u32 s[100002];

int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

    cin >> t;

    for (u32 ti = 0; ti < t; ti++) {
        u32 u = 0;
        u32 d = 0;
        u32 e = 0;

        i32 m, k;
        cin >> m >> k;
        for (u32 i = 1; i <= k; i++) {
            r[i] = 0;
            s[i] = 0;
        }

        for (u32 i = 1; i <= k; i++) {
            cin >> a[i];
        }

        for (i32 i = 0; i < m - 1; i++) {
            cin >> A[i].first >> A[i].second;
        }

        for (i32 j = 0; j < m - 1; j++) {
            if (!e && A[j].second) {
                e = 1;

                for (u32 i = j; i < m - 1; i++) {
                    s[A[i].first] = 1;
                }

                for (u32 i = 1; i <= k; i++) {
                    if (a[i] <= u && !s[i]) {
                        r[i] = 1;
                    }
                }

                d = INF;
                for (u32 i = 1; i <= k; i++) {
                    if (!s[i] && a[i] < d) {
                        d = a[i];
                    }
                }
            }

            if (A[j].first == 0) {
                u++;
                continue;
            }

            a[A[j].first]--;
        }

        for (u32 i = 1; i <= k; i++) {
            if (r[i]) {
                cout << 'Y';
                continue;
            }
            if (a[i] > u - d) {
                cout << 'N';
            } else {
                cout << 'Y';
            }
        }
        cout << endl;
    }

    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#define INF 1000000000
#define fi first
#define se second
#define N 100005
#define debug(x) cout<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int T;
int n,k;
int a[N],s1,s2,b[N];
int vis[N];
int main()
{
    int i,flag,t1,t2,j,mn;
    cin>>T;
    int tt=T,te=0;
    while(T--)
    {
        te++;
        s1=s2=flag=0;
        mn=INF;
        scanf("%d%d",&n,&k);
        n--;
        for(i=1;i<=k;i++)
            scanf("%d",&a[i]),vis[i]=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&t1,&t2);
            if(!flag&&t2)
            {
                flag=1;
                s2=s1;
                for(j=1;j<=k;j++)
                    b[j]=a[j];
            }
            if(t1==0)
                s1++;
            else
                a[t1]--;
        }
        if(!flag) mn=0;
        else
            for(i=1;i<=k;i++)
                mn=min(mn,b[i]);
        for(i=1;i<=k;i++)
        {
            if(flag)
                if(a[i]==b[i])
                    if(s2>=b[i])
                        vis[i]=1;
            if(s1-mn>=a[i])
                vis[i]=2;
            if(tt==30633&&te==18132&&i==2)
                cout<<vis[i]<<' ';
            if(vis[i])
                printf("Y");
            else printf("N");
        }
        printf("\n");
    }
    return 0;
}
// davidlee1999WTK 2015/
// srO myk Orz
//ios::sync_with_stdio(false);


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#define INF 1000000000
#define fi first
#define se second
#define N 100005
#define debug(x) cout<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int T;
int n,k;
int a[N],s1,s2,b[N];
bool vis[N];
int main()
{
    int i,flag,t1,t2,j,mn;
    cin>>T;
    while(T--)
    {
        s1=s2=flag=0;
        mn=INF;
        scanf("%d%d",&n,&k);
        n--;
        for(i=1;i<=k;i++)
            scanf("%d",&a[i]),vis[i]=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&t1,&t2);
            if(!flag&&t2)
            {
                flag=1;
                s2=s1;
                for(j=1;j<=k;j++)
                    b[j]=a[j];
            }
            if(t1==0)
                s1++;
            else
                a[t1]--;
        }
        if(!flag) mn=0;
        else
            for(i=1;i<=k;i++)
                mn=min(mn,b[i]);
        for(i=1;i<=k;i++)
        {
            if(flag)
                if(a[i]==b[i])
                    if(s2>=b[i])
                        vis[i]=1;
            if(s1-mn>=a[i])
                vis[i]=1;
            if(vis[i])
                printf("Y");
            else printf("N");
        }
        printf("\n");
    }
    return 0;
}
// davidlee1999WTK 2015/
// srO myk Orz
//ios::sync_with_stdio(false);


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#define INF 1000000000
#define fi first
#define se second
#define N 100005
#define debug(x) cout<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int T;
int n,k;
int a[N],s1,s2,b[N];
int vis[N];
int main()
{
    int i,flag,t1,t2,j,mn;
    cin>>T;
    int tt=T,te=0;
    while(T--)
    {
        te++;
        s1=s2=flag=0;
        mn=INF;
        scanf("%d%d",&n,&k);
        n--;
        for(i=1;i<=k;i++)
            scanf("%d",&a[i]),vis[i]=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&t1,&t2);
            if(!flag&&t2)
            {
                flag=1;
                s2=s1;
                for(j=1;j<=k;j++)
                    b[j]=a[j];
            }
            if(t1==0)
                s1++;
            else
                a[t1]--;
        }
        if(!flag) mn=0;
        else
            for(i=1;i<=k;i++)
                mn=min(mn,b[i]);
        for(i=1;i<=k;i++)
        {
            if(flag)
                if(a[i]==b[i])
                    if(s2>=b[i])
                        vis[i]=1;
            if(s1-mn>=a[i])
                vis[i]=2;
            if(tt==30633&&te==18132&&i==2)
                cout<<flag<<' ';
            if(vis[i])
                printf("Y");
            else printf("N");
        }
        printf("\n");
    }
    return 0;
}
// davidlee1999WTK 2015/
// srO myk Orz
//ios::sync_with_stdio(false);


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#define INF 1000000000
#define fi first
#define se second
#define N 100005
#define debug(x) cout<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int T;
int n,k;
int a[N],s1,s2,b[N];
int vis[N];
int main()
{
    int i,flag,t1,t2,j,mn;
    cin>>T;
    int tt=T,te=0;
    while(T--)
    {
        te++;
        s1=s2=flag=0;
        mn=INF;
        scanf("%d%d",&n,&k);
        n--;
        for(i=1;i<=k;i++)
            scanf("%d",&a[i]),vis[i]=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&t1,&t2);
            if(!flag&&t2)
            {
                flag=1;
                s2=s1;
                for(j=1;j<=k;j++)
                    b[j]=a[j];
            }
            if(t1==0)
                s1++;
            else
                a[t1]--;
        }
        if(!flag) mn=0;
        else
            for(i=1;i<=k;i++)
                if(a[i]==b[i])
                    mn=min(mn,b[i]);
        for(i=1;i<=k;i++)
        {
            if(flag)
                if(a[i]==b[i])
                    if(s2>=b[i])
                        vis[i]=1;
            if(s1-mn>=a[i])
                vis[i]=2;
            //if(tt==30633&&te==18132&&i==2)
                //cout<<flag<<' ';
            if(vis[i])
                printf("Y");
            else printf("N");
        }
        printf("\n");
    }
    return 0;
}
// davidlee1999WTK 2015/
// srO myk Orz
//ios::sync_with_stdio(false);


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#define INF 1000000000
#define fi first
#define se second
#define N 100005
#define debug(x) cout<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int T;
int n,k;
int a[N],s1,s2,b[N];
bool vis[N];
int main()
{
    int i,flag,t1,t2,j,mn;
    cin>>T;
    while(T--)
    {
        s1=s2=flag=0;
        mn=INF;
        scanf("%d%d",&n,&k);
        n--;
        for(i=1;i<=k;i++)
            scanf("%d",&a[i]),vis[i]=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&t1,&t2);
            if(!flag&&t2)
            {
                flag=1;
                s2=s1;
                for(j=1;j<=k;j++)
                    b[j]=a[j];
            }
            if(t1==0)
                s1++;
            else
                a[t1]--;
        }
        if(!flag) mn=0;
        else
            for(i=1;i<=k;i++)
                mn=min(mn,b[i]);
        for(i=1;i<=k;i++)
        {
            if(a[i]==b[i])
                if(s2>=b[i])
                    vis[i]=1;
            if(s1-mn>=a[i])
                vis[i]=1;
            if(vis[i])
                printf("Y");
            else printf("N");
        }
        printf("\n");
    }
    return 0;
}
// davidlee1999WTK 2015/
// srO myk Orz
//ios::sync_with_stdio(false);


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#define INF 1000000000
#define fi first
#define se second
#define N 100005
#define debug(x) cout<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int T;
int n,k;
int a[N],s1,s2,b[N];
int vis[N];
int main()
{
    int i,flag,t1,t2,j,mn;
    cin>>T;
    int tt=T,te=0;
    while(T--)
    {
        te++;
        s1=s2=flag=0;
        mn=INF;
        scanf("%d%d",&n,&k);
        n--;
        for(i=1;i<=k;i++)
            scanf("%d",&a[i]),vis[i]=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&t1,&t2);
            if(!flag&&t2)
            {
                flag=1;
                s2=s1;
                for(j=1;j<=k;j++)
                    b[j]=a[j];
            }
            if(t1==0)
                s1++;
            else
                a[t1]--;
        }
        if(!flag) mn=0;
        else
            for(i=1;i<=k;i++)
                mn=min(mn,b[i]);
        for(i=1;i<=k;i++)
        {
            if(flag)
                if(a[i]==b[i])
                    if(s2>=b[i])
                        vis[i]=1;
            if(s1-mn>=a[i])
                vis[i]=2;
            if(tt==30633&&te==18132)
                cout<<vis[i]<<' ';
            if(vis[i])
                printf("Y");
            else printf("N");
        }
        printf("\n");
    }
    return 0;
}
// davidlee1999WTK 2015/
// srO myk Orz
//ios::sync_with_stdio(false);


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <hash_map>

using namespace std;
typedef long long ll;

int main(){
    int t;
    cin>>t;
    while(t--){
        int m, k;
        scanf("%d %d", &m, &k);
        vector<char> res(k, true);
        vector<int> arr(k), b(k, 0);
        for(int i=0; i<k; i++){
            scanf("%d", &arr[i]);
        }
        vector<pair<int, int> > q(m - 1);
        for(int i=0; i<m - 1; i++){
            scanf("%d %d", &q[i].first, &q[i].second);
            if(q[i].first != 0)
                b[q[i].first - 1]++;
        }
        int cnt = 0;
        bool fl = false;

        for(int i=0; i<m - 1; i++){
            if(q[i].second == 1){
                if(!fl){
                    fl = true;
                    int mn = 1e9;
                    for(int j=0; j<k; j++){
                        if(b[j] != 0)
                            continue;
                        mn = min(mn, arr[j]);
                        if(arr[j] <= cnt)
                            res[j] = false;
                    }
                    cnt -= mn;
                }
            }

            if(q[i].first == 0){
                cnt++;
            }
            else{
                int j = q[i].first - 1;
                arr[j]--;
                b[j]--;
                if(arr[j] == 0)
                    fl = true;
            }
        }

        for(int i=0; i<k; i++){
            if(arr[i] <= cnt)
                res[i] = false;
        }

        for(int i=0; i<k; i++){
            if(res[i])
                printf("N");
            else
                printf("Y");
        }
        printf("\n");
    }

    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <sstream>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <ctime>
#include <bitset>
#include <cassert>
#include <iomanip>
using namespace std;

#define forn(i,n)  for(int i = 0; i < (n); ++i)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define fskfs x
#define sfdjh y
#define pii pair<int, int>
#define mod 1000000007
#define inf 2000000000
#define eps 1e-8
#define sq(x) ((x) * (x))
typedef long long ll;

int m, k;
vector<int>a, b;
void init ()
{
    cin >> m >> k;
    a.resize(k);
    b.resize(k);
    for (int i = 0; i < k; ++i)
        cin >> a[i];
}

int get_min ()
{
    int pos = 0;
    for (int i = 0; i < k; ++i)
    {
        if (a[pos] > a[i])
            pos = i;
    }
    return pos;
}
void solve ()
{
    int val = 0, r, t, flag = 0;
    for (int i = 0; i < m - 1; ++i)
    {
        cin >> t >> r;
        if (t)
            a[t - 1]--;
        else
            ++val;
        if (r && !flag)
        {
            b = a;
            flag = 1;
        }
    }
    int mn = (int)1e9;
    if (flag)
    {
        for (int i = 0; i < k; ++i)
        {
            if (a[i] == b[i])
                mn = min(mn, b[i]);
        }
        val -= mn;
    }
    for (int i = 0; i < k; ++i)
    {
        if (val >= a[i])
            cout << 'Y';
        else
            cout << 'N';
    }
    cout << '\n';
}
int main()
{
    //freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0);
    int T;
    cin >> T;
    while (T)
    {
        init();
        solve();
        --T;
    }
 return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <sstream>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <ctime>
#include <bitset>
#include <cassert>
#include <iomanip>
using namespace std;

#define forn(i,n)  for(int i = 0; i < (n); ++i)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define fskfs x
#define sfdjh y
#define pii pair<int, int>
#define mod 1000000007
#define inf 2000000000
#define eps 1e-8
#define sq(x) ((x) * (x))
typedef long long ll;

int m, k;
vector<int>a, b;
void init ()
{
    cin >> m >> k;
    a.resize(k);
    b.resize(k);
    for (int i = 0; i < k; ++i)
        cin >> a[i];
}

int get_min ()
{
    int pos = 0;
    for (int i = 0; i < k; ++i)
    {
        if (a[pos] > a[i])
            pos = i;
    }
    return pos;
}
void solve ()
{
    int val = 0, r, t, flag = 0;
    for (int i = 0; i < m - 1; ++i)
    {
        cin >> t >> r;
        if (r && !flag)
        {
            b = a;
            flag = 1;
        }

        if (t)
            a[t - 1]--;
        else
            ++val;
    }
    int mn = (int)1e9;
    if (flag)
    {
        for (int i = 0; i < k; ++i)
        {
            if (a[i] == b[i])
                mn = min(mn, b[i]);
        }
        val -= mn;
    }
    for (int i = 0; i < k; ++i)
    {
        if (val >= a[i])
            cout << 'Y';
        else
            cout << 'N';
    }
    cout << '\n';
}
int main()
{
    //freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0);
    int T;
    cin >> T;
    while (T)
    {
        init();
        solve();
        --T;
    }
 return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <sstream>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <ctime>
#include <bitset>
#include <cassert>
#include <iomanip>
using namespace std;

#define forn(i,n)  for(int i = 0; i < (n); ++i)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define fskfs x
#define sfdjh y
#define pii pair<int, int>
#define mod 1000000007
#define inf 2000000000
#define eps 1e-8
#define sq(x) ((x) * (x))
typedef long long ll;

int m, k;
vector<int>a, b;
void init ()
{
    cin >> m >> k;
    a.resize(k);
    b.resize(k);
    for (int i = 0; i < k; ++i)
        cin >> a[i];
}

int get_min ()
{
    int pos = 0;
    for (int i = 0; i < k; ++i)
    {
        if (a[pos] > a[i])
            pos = i;
    }
    return pos;
}
void solve ()
{
    int val = 0, r, t, flag = 0;
    for (int i = 0; i < m - 1; ++i)
    {
        cin >> t >> r;
        if (r && !flag)
        {
            b = a;
            flag = 1;
        }

        if (t)
            a[t - 1]--;
        else
            ++val;
    }
    if (flag)
    {
        int pos = 0, mn = (int)1e9;
        for (int i = 0; i < k; ++i)
        {
            if (a[i] == b[i] && a[i] < mn)
            {
                mn = a[i];
                pos = i;
            }
        }
        val -= mn;
        a[pos] = 0;
    }
    for (int i = 0; i < k; ++i)
    {
        if (val >= a[i])
            cout << 'Y';
        else
            cout << 'N';
    }
    cout << '\n';
}
int main()
{
    //freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0);
    int T;
    cin >> T;
    while (T)
    {
        init();
        solve();
        --T;
    }
 return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <sstream>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <ctime>
#include <bitset>
#include <cassert>
#include <iomanip>
using namespace std;

#define forn(i,n)  for(int i = 0; i < (n); ++i)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define fskfs x
#define sfdjh y
#define pii pair<int, int>
#define mod 1000000007
#define inf 2000000000
#define eps 1e-8
#define sq(x) ((x) * (x))
typedef long long ll;

int m, k;
vector<int>a, b;
void init ()
{
    cin >> m >> k;
    a.resize(k);
    b.resize(k);
    for (int i = 0; i < k; ++i)
        cin >> a[i];
}

int get_min ()
{
    int pos = 0;
    for (int i = 0; i < k; ++i)
    {
        if (a[pos] > a[i])
            pos = i;
    }
    return pos;
}
void solve ()
{
    int val = 0, r, t, flag = 0, cnt;
    for (int i = 0; i < m - 1; ++i)
    {
        cin >> t >> r;
        if (r && !flag)
        {
            cnt = val;
            b = a;
            flag = 1;
        }

        if (t)
            a[t - 1]--;
        else
            ++val;
    }
    if (flag)
    {
        int mn = (int)1e9;
        for (int i = 0; i < k; ++i)
        {
            if (a[i] == b[i])
            {
                mn = min(mn, b[i]);
                if (cnt >= b[i])
                    a[i] = 0;
            }
        }
        val -= mn;
    }
    for (int i = 0; i < k; ++i)
    {
        if (val >= a[i])
            cout << 'Y';
        else
            cout << 'N';
    }
    cout << '\n';
}
int main()
{
    //freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0);
    int T;
    cin >> T;
    while (T)
    {
        init();
        solve();
        --T;
    }
 return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <sstream>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <ctime>
#include <bitset>
#include <cassert>
#include <iomanip>
using namespace std;

#define forn(i,n)  for(int i = 0; i < (n); ++i)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define fskfs x
#define sfdjh y
#define pii pair<int, int>
#define mod 1000000007
#define inf 2000000000
#define eps 1e-8
#define sq(x) ((x) * (x))
typedef long long ll;

int m, k;
vector<int>a, b;
void init ()
{
    cin >> m >> k;
    a.resize(k);
    b.resize(k);
    for (int i = 0; i < k; ++i)
        cin >> a[i];
}

int get_min ()
{
    int pos = 0;
    for (int i = 0; i < k; ++i)
    {
        if (a[pos] > a[i])
            pos = i;
    }
    return pos;
}
void solve ()
{
    int val = 0, r, t, flag = 0;
    for (int i = 0; i < m - 1; ++i)
    {
        cin >> t >> r;
        if (r && !flag)
        {
            b = a;
            flag = 1;
        }

        if (t)
            a[t - 1]--;
        else
            ++val;
    }
    if (flag)
    {
        int pos = 0, mn = (int)1e9;
        for (int i = 0; i < k; ++i)
        {
            if (a[i] == b[i] && b[i] < mn)
            {
                mn = b[i];
                pos = i;
            }
        }
        val -= mn;
        a[pos] = 0;
    }
    for (int i = 0; i < k; ++i)
    {
        if (val >= a[i])
            cout << 'Y';
        else
            cout << 'N';
    }
    cout << '\n';
}
int main()
{
    //freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0);
    int T;
    cin >> T;
    while (T)
    {
        init();
        solve();
        --T;
    }
 return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <sstream>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <ctime>
#include <bitset>
#include <cassert>
#include <iomanip>
using namespace std;

#define forn(i,n)  for(int i = 0; i < (n); ++i)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define fskfs x
#define sfdjh y
#define pii pair<int, int>
#define mod 1000000007
#define inf 2000000000
#define eps 1e-8
#define sq(x) ((x) * (x))
typedef long long ll;

int m, k;
vector<int>a;
void init ()
{
    cin >> m >> k;
    a.resize(k);
    for (int i = 0; i < k; ++i)
        cin >> a[i];
}

int get_min ()
{
    int pos = 0;
    for (int i = 0; i < k; ++i)
    {
        if (a[pos] > a[i])
            pos = i;
    }
    return pos;
}
void solve ()
{
    int val = 0, r, t, flag = 0;
    for (int i = 0; i < m - 1; ++i)
    {
        cin >> t >> r;
        if (t)
            a[t - 1]--;
        else
            ++val;
        if (r && !flag)
        {
            int pos = get_min();
            val -= a[pos];
            a[pos] = 0;
            flag = 1;
        }
    }
    for (int i = 0; i < k; ++i)
    {
        if (val >= a[i])
            cout << 'Y';
        else
            cout << 'N';
    }
    cout << '\n';
}
int main()
{
    //freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0);
    int T;
    cin >> T;
    while (T)
    {
        init();
        solve();
        --T;
    }
 return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <sstream>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <ctime>
#include <bitset>
#include <cassert>
#include <iomanip>
using namespace std;

#define forn(i,n)  for(int i = 0; i < (n); ++i)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define fskfs x
#define sfdjh y
#define pii pair<int, int>
#define mod 1000000007
#define inf 2000000000
#define eps 1e-8
#define sq(x) ((x) * (x))
typedef long long ll;

int m, k;
vector<int>a, b;
void init ()
{
    cin >> m >> k;
    a.resize(k);
    b.resize(k);
    for (int i = 0; i < k; ++i)
        cin >> a[i];
}

int get_min ()
{
    int pos = 0;
    for (int i = 0; i < k; ++i)
    {
        if (a[pos] > a[i])
            pos = i;
    }
    return pos;
}
void solve ()
{
    int val = 0, r, t, flag = 0;
    for (int i = 0; i < m - 1; ++i)
    {
        cin >> t >> r;
        if (r && !flag)
        {
            b = a;
            flag = 1;
        }

        if (t)
            a[t - 1]--;
        else
            ++val;
    }
    if (flag)
    {
        int pos = 0;
        for (int i = 0; i < k; ++i)
        {
            if (a[i] == b[i] && a[pos] > a[i])
                pos = i;
        }
        val -= a[pos];
        a[pos] = 0;
    }
    for (int i = 0; i < k; ++i)
    {
        if (val >= a[i])
            cout << 'Y';
        else
            cout << 'N';
    }
    cout << '\n';
}
int main()
{
   // freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0);
    int T;
    cin >> T;
    while (T)
    {
        init();
        solve();
        --T;
    }
 return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <sstream>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <ctime>
#include <bitset>
#include <cassert>
#include <iomanip>
using namespace std;

#define forn(i,n)  for(int i = 0; i < (n); ++i)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define fskfs x
#define sfdjh y
#define pii pair<int, int>
#define mod 1000000007
#define inf 2000000000
#define eps 1e-8
#define sq(x) ((x) * (x))
typedef long long ll;

int m, k;
vector<int>a, b;
void init ()
{
    cin >> m >> k;
    a.resize(k);
    b.resize(k);
    for (int i = 0; i < k; ++i)
        cin >> a[i];
}

int get_min ()
{
    int pos = 0;
    for (int i = 0; i < k; ++i)
    {
        if (a[pos] > a[i])
            pos = i;
    }
    return pos;
}
void solve ()
{
    int val = 0, r, t, flag = 0, cnt;
    for (int i = 0; i < m - 1; ++i)
    {
        cin >> t >> r;
        if (r && !flag)
        {
            cnt = val;
            b = a;
            flag = 1;
        }

        if (t)
            a[t - 1]--;
        else
            ++val;
    }
    if (flag)
    {
        int mn = (int)1e9;
        for (int i = 0; i < k; ++i)
        {
            if (a[i] == b[i] && b[i] < mn)
            {
                if (cnt >= b[i])
                    a[i] = 0;
                mn = b[i];
            }
        }
        val -= mn;
    }
    for (int i = 0; i < k; ++i)
    {
        if (val >= a[i])
            cout << 'Y';
        else
            cout << 'N';
    }
    cout << '\n';
}
int main()
{
    //freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0);
    int T;
    cin >> T;
    while (T)
    {
        init();
        solve();
        --T;
    }
 return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
//#define endl '\n'
#pragma warning (disable : 4996)

using namespace std;

#define lli long long int
#define MP make_pair

const int N = (int)(2e6 + 20);

bool canFirst[N];
int needFreeToFirst[N];
int cnt[N];

int main()
{
#ifdef FILE_IO
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int T;
    scanf("%d", &T);
    for (int qq = 0; qq < T; ++qq) {
        int m, k;
        scanf("%d%d", &m, &k);
        //понулить с прошлого раза - вроде бы нечего нулить
        for (int i = 1; i <= k; ++i) {
            canFirst[i] = 0;
            needFreeToFirst[i] = 0;
            cnt[i] = 0;
        }

        for (int i = 1; i <= k; ++i) scanf("%d", &cnt[i]);

        int free = 0;
        bool firstAngry = false;
        for (int i = 1; i < m; ++i) {
            int type, angry;
            scanf("%d%d", &type, &angry);

            if (angry == 1 && !firstAngry) {
                firstAngry = true;
                for (int j = 1; j <= k; ++j) {
                    canFirst[j] = (cnt[j] <= free);
                    needFreeToFirst[j] = cnt[j];
                }
            }

            if (type == 0) {
                ++free;
            } else {
                canFirst[type] = false;
                cnt[type]--;
            }
        }

        int minForFirst = 0;
        if (firstAngry) {
            minForFirst = N;
            for (int j = 1; j <= k; ++j) {
                if (canFirst[j])
                    minForFirst = min(minForFirst, needFreeToFirst[j]);
            }
        }

        for (int j = 1; j <= k; ++j) {
            if (canFirst[j] || (cnt[j] <= free - minForFirst)) printf("Y");
            else printf("N");
        }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
	long long a[100003][2];
int main()
{
	int t;
	cin>>t;
	long long m, k;
	for (int l=1; l<=t; l++)
	{
	cin>>m>>k;
	for (int i=1; i<=k; i++)
	{
		cin>>a[i][0];
		a[i][1]=0;
	}
	long long fl=1;
	for (int i=0; i<m-1; i++)
	{
		long long t, r;
		if (fl)
		{
			cin>>t>>r;
			a[t][0]--;
			if (r==1)
			{
				for (int j=1; j<=k; j++)
					if (a[j][0]<=(-a[0][0]))
						a[j][1]=1;
				fl=0;
			}
		}
		else
		{
			long long t, r;
			cin>>t>>r;
			a[t][0]--;
			a[t][1]=0;
		}
	}
	long long min=1000000;
	for (int i=1; i<=k; i++)
		if (a[i][1])
			if (a[i][1]<min)
				min=a[i][1];
	long long kol;
	if (min==1000000)
		kol=-a[0][0];
	else
		kol=-a[0][0]-min;
	for (int i=1; i<=k; i++)
		if (a[i][1]||(a[i][0]<=kol))
			cout<<"Y";
		else
			cout<<"N";
	cout<<endl;
	}
	return 0;
}


def ris():
    return map(int, input().split())

def testCase():
    m, k = ris()
    q = 0
    a = list(ris())
    some_is_out = False
    tmp = set()
    for i in range(m - 1):
        t, r = ris()
        t -= 1
        if r == 1 and not some_is_out:
            some_is_out = True
            tmp = tmp.union(set(filter(lambda x: a[x] <= q, range(k))))
        if t == -1:
            q += 1
        else:
            if t in tmp:
                tmp.remove(t)
            a[t] -= 1
            if a[t] < 0:
                a[t] = 0
                q += 1
    if tmp:
        q -= min(map(lambda x: a[x], tmp))
    print("".join(list(map(lambda x: 'Y' if a[x] - q <= 0 or x in tmp else 'N', range(len(a))))))

for i in range(int(input())):
    input()
    testCase()


def ris():
    return map(int, input().split())

def testCase():
    m, k = ris()
    q = 0
    a = list(ris())
    some_is_out = False
    tmp = set()
    for i in range(m - 1):
        t, r = ris()
        t -= 1
        if r == 1 and not some_is_out:
            some_is_out = True
            tmp.union(set(filter(lambda x: a[x] <= q, range(k))))
        if t == -1:
            q += 1
        else:
            if t in tmp:
                tmp.remove(t)
            a[t] -= 1
            if a[t] < 0:
                a[t] = 0
                q += 1
    if tmp:
        q -= min(tmp)
    print("".join(list(map(lambda x: 'Y' if a[x] - q <= 0 or x in tmp else 'N', range(len(a))))))

for i in range(int(input())):
    input()
    testCase()


n=int(input())
for i in range(n):
    input().strip()
    q,w=map(int,input().strip().split())
    kol=list(map(int,input().strip().split()))
    r=[]
    e=[]
    for ii in range(q-1):
        a,s=map(int,input().strip().split())
        a-=1
        r.append(a)
        e.append(s)
    rw=[0 for uu in kol]
    for ii in range(q-1):
        if r[ii]!=-1:
            rw[r[ii]]+=1
    nd=[0 for uu in kol]
    l=[uu for uu in kol]
    rez=[False for uu in kol]
    qw=0
    tr=True
    for ii in range(q-1):
        if e[ii]==1 and tr:
            su=[]
            for iii in range(w):
                if nd[iii]<rw[iii]:
                    continue
                if l[iii]>qw:
                    continue
                su.append(iii)
            if len(su)==0:
                raise AssertionError
            for iii in su:
                rez[iii]=True
            qw-=min(map(lambda iii:l[iii],su))
            tr=False
        if r[ii]!=-1:
            l[r[ii]]-=1
            nd[r[ii]]+=1
            if l[r[ii]]==0:
                tr=False
        else:
            qw+=1
    for iii in range(w):
        if l[iii]<=qw:
            rez[iii]=True
    print(''.join(map(lambda x:'Y' if x else 'N',rez)))


import sys
n=int(input())
for i in range(n):
    sys.stdin.readline()
    q,w=map(int,sys.stdin.readline().split())
    kol=list(map(int,sys.stdin.readline().split()))
    r=[]
    e=[]
    for ii in range(q-1):
        a,s=map(int,sys.stdin.readline().split())
        a-=1
        r.append(a)
        e.append(s)
    rw=[0 for uu in kol]
    for ii in range(q-1):
        if r[i]!=-1:
            rw[r[i]]+=1
    nd=[0 for uu in kol]
    l=[uu for uu in kol]
    rez=[False for uu in kol]
    qw=0
    tr=True
    for ii in range(q-1):
        if e[i]==1 and tr:
            su=[]
            for iii in range(w):
                if nd[iii]<rw[iii]:
                    continue
                if l[iii]>qw:
                    continue
                su.append(iii)
            if len(su)==0:
                raise AssertionError
            for iii in su:
                rez[iii]=True
            qw-=min(map(lambda iii:l[iii],su))
            tr=False
        if r[ii]!=-1:
            l[r[ii]]-=1
            nd[r[ii]]+=1
            if l[r[ii]]==0:
                tr=False
        else:
            qw+=1
    for iii in range(w):
        if l[iii]<=qw:
            rez[iii]=True
    print(''.join(map(lambda x:'Y' if x else 'N',rez)))


import sys
n=int(input())
for i in range(n):
    sys.stdin.readline()
    q,w=map(int,sys.stdin.readline().split())
    kol=list(map(int,sys.stdin.readline().split()))
    r=[]
    e=[]
    for ii in range(q-1):
        a,s=map(int,sys.stdin.readline().split())
        a-=1
        r.append(a)
        e.append(s)
    rw=[0 for uu in kol]
    for ii in range(q-1):
        if r[ii]!=-1:
            rw[r[ii]]+=1
    nd=[0 for uu in kol]
    l=[uu for uu in kol]
    rez=[False for uu in kol]
    qw=0
    tr=True
    for ii in range(q-1):
        if e[ii]==1 and tr:
            su=[]
            for iii in range(w):
                if nd[iii]<rw[iii]:
                    continue
                if l[iii]>qw:
                    continue
                su.append(iii)
            if len(su)==0:
                raise AssertionError
            for iii in su:
                rez[iii]=True
            qw-=min(map(lambda iii:l[iii],su))
            tr=False
        if r[ii]!=-1:
            l[r[ii]]-=1
            nd[r[ii]]+=1
            if l[r[ii]]==0:
                tr=False
        else:
            qw+=1
    for iii in range(w):
        if l[iii]<=qw:
            rez[iii]=True
    sys.stdout.write(''.join(map(lambda x:'Y' if x else 'N',rez))+'\n')


n=int(input())
for i in range(n):
    input().strip()
    q,w=map(int,input().strip().split())
    kol=list(map(int,input().strip().split()))
    r=[]
    e=[]
    for ii in range(q-1):
        a,s=map(int,input().strip().split())
        a-=1
        r.append(a)
        e.append(s)
    rw=[0 for uu in kol]
    for ii in range(q-1):
        if r[i]!=-1:
            rw[r[i]]+=1
    nd=[0 for uu in kol]
    l=[uu for uu in kol]
    rez=[False for uu in kol]
    qw=0
    tr=True
    for ii in range(q-1):
        if e[i]==1 and tr:
            su=[]
            for iii in range(w):
                if nd[iii]<rw[iii]:
                    continue
                if l[iii]>qw:
                    continue
                su.append(iii)
            if len(su)==0:
                raise AssertionError
            for iii in su:
                rez[iii]=True
            qw-=min(map(lambda iii:l[iii],su))
            tr=False
        if r[ii]!=-1:
            l[r[ii]]-=1
            nd[r[ii]]+=1
            if l[r[ii]]==0:
                tr=False
        else:
            qw+=1
    for iii in range(w):
        if l[iii]<=qw:
            rez[iii]=True
    print(''.join(map(lambda x:'Y' if x else 'N',rez)))


t = int(input())
for i in range(t):
    input()
    m,k = map(int,input().split())
    ak = list(map(int,input().split()))
    ak2 = [0]*k
    tjrj = [list(map(int,input().split())) for j in range(m-1)]
    num = 0
    num2 = 0
    num3 = 100002
    for j in range(m-1):
        if num2 == 1 or tjrj[j][1] == 0:
            if tjrj[j][0] != 0:
                ak[tjrj[j][0]-1] -= 1
            else:
                num += 1
        else:
            for z in range(k):
                    if ak[z] - num < 1:
                        ak2[z] = 1
            num2 = 1
            if tjrj[j][0] != 0:
                ak[tjrj[j][0]-1] -= 1
            else:
                num += 1
            for f in range(j,m-1):
                if tjrj[f][0] != 0:
                    ak2[tjrj[f][0]-1] = 0
            for f in range(k):
                if ak2[f] == 1:
                    if num3 > ak[f]:
                        num3 = ak[f]
            num -= num3
    for z in range(k):
        if ak[z] - num < 1 or ak2[z] == 1:
            print("Y",end="")
        else:
            print("N",end="")
    print()


t = int(input())
for i in range(t):
    input()
    m,k = map(int,input().split())
    ak = list(map(int,input().split()))
    ak2 = [0]*k
    tjrj = [list(map(int,input().split())) for j in range(m-1)]
    num = 0
    num2 = 0
    for j in range(m-1):
        if num2 == 1 or tjrj[j][1] == 0:
            if tjrj[j][0] != 0:
                ak[tjrj[j][0]-1] -= 1
            else:
                num += 1
        else:
            for z in range(k):
                    if ak[z] - num < 1:
                        ak2[z] = 1
            num2 = 1
            if tjrj[j][0] != 0:
                ak[tjrj[j][0]-1] -= 1
            else:
                num += 1
            for f in range(j,m-1):
                if tjrj[f][0] != 0:
                    ak2[tjrj[f][0]-1] = 0
    for z in range(k):
        if ak[z] - num < 1 or ak2[z] == 1:
            print("Y",end="")
        else:
            print("N",end="")
    print()


import sys

t = int(input())

for i in range(t):
    remove_from_all = 0
    input()
    m, k = (int(x) for x in input().split())
    dishes = [int(x) for x in input().split()]
    inputs = []
    for j in range(m - 1):
        t, r = (int(x) for x in input().split())
        inputs.append((t - 1, r))
    seen_upset = False
    for i, v in enumerate(inputs):
        t, r = v
        if r == 1 and not seen_upset:
            impossible = set()
            for j in range(i, len(inputs)):
                _t, _r = inputs[j]
                impossible.add(_t)
            for j in range(len(dishes)):
                if dishes[j] > remove_from_all:
                    impossible.add(j)
            minimal = float("inf")
            for j in range(len(dishes)):
                if j not in impossible:
                    minimal = min(dishes[j], minimal)
                    dishes[j] = 0
            remove_from_all -= minimal
            seen_upset = True
        if t == -1:
            remove_from_all += 1
        else:
            dishes[t] -= 1
    for j in dishes:
        sys.stdout.write("Y" if j - remove_from_all <= 0 else "N")
    print("")


import sys

t = int(input())

for i in range(t):
	remove_from_all = 0
	input()
	m, k = (int(x) for x in input().split())
	dishes = [int(x) for x in input().split()]
	for j in range(m - 1):
		t, r = (int(x) for x in input().split())
		if t == 0:
			remove_from_all += 1
		else:
			dishes[t - 1] -= 1
	for j in dishes:
		sys.stdout.write("Y" if j - remove_from_all <= 0 else "N")
	print("")


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    ll n;
    cin >> n;

    string cur;
    for(ll i = 0; i < n; i++) {
        cin >> cur;
        if(cur.substr(cur.length() - 2, 2) == "po") {
            cout << "FILIPINO" << endl;
        } else if(cur.substr(cur.length() - 5, 5) == "mnida"){
            cout << "KOREAN" << endl;
        } else {
            cout << "JAPANESE" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int n;
    cin >> n;

    string cur;
    for(int i = 0; i < n; i++) {
        cin >> cur;
        if(cur.substr(cur.length() - 2, 2) == "po") {
            printf("FILIPINO\n");
        } else if(cur.substr(cur.length() - 5, 5) == "mnida"){
            printf("KOREAN\n");
        } else {
            printf("JAPANESE\n");
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int n;
    cin >> n;

    for(int i = 0; i < n; i++) {
        string cur;
        cin >> cur;
       // cout << cur << endl;
        if(cur.length() >= 2 && cur.substr(cur.length() - 2, 2) == "po") {
            printf("FILIPINO\n");
        } else if(cur.length() >= 5 && cur.substr(cur.length() - 5, 5) == "mnida"){
            printf("KOREAN\n");
        } else {
            printf("JAPANESE\n");
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int n;
    cin >> n;

    string cur;
    for(int i = 0; i < n; i++) {
        cin >> cur;
        if(cur.substr(cur.length() - 2, 2) == "po") {
            cout << "FILIPINO" << endl;
        } else if(cur.substr(cur.length() - 5, 5) == "mnida"){
            cout << "KOREAN" << endl;
        } else {
            cout << "JAPANESE" << endl;
        }
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <ctime>
#include <string>

using namespace std;

int main() {
	int cases;
	cin >> cases;
	for (int i = 0; i < cases; i++) {
		string word;
		cin >> word;
		int length = word.size();
		if (word.substr(length - 2, length - 1) == "po") {
			cout << "FILIPINO" << endl;
		}
		else if (word.substr(length - 4, length - 1) == "desu"
			|| word.substr(length - 4, length - 1) == "masu") {
			cout << "JAPANESE" << endl;
		}
		else
			cout << "KOREAN" << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <ctime>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

int main() {
	int cases;
	cin >> cases;
	for (int i = 0; i < cases; i++) {
		string word;
		cin >> word;
		int length = word.size();
		if (word.substr(length - 2, length - 1) == "po") {
			cout << "FILIPINO" << endl;
		}
		else if (word.substr(length - 4, length - 1) == "desu"
			|| word.substr(length - 4, length - 1) == "masu") {
			cout << "JAPANESE" << endl;
		}
		else
			cout << "KOREAN" << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <ctime>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

int main() {
	int cases;
	cin >> cases;
	for (int i = 0; i < cases; i++) {
		string word;
		cin >> word;
		int length = word.size();
		if (word.substr(length - 2, length) == "po") {
			cout << "FILIPINO" << endl;
		}
		else if (word.substr(length - 4, length) == "desu")
			cout << "JAPANESE" << endl;
		else if (word.substr(length - 4, length) == "masu")
			cout << "JAPANESE" << endl;
		else
			cout << "KOREAN" << endl;
	}
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        //char a[4];
       // int k=0;
        cin>>s;
       // for(int i=s.end()-1;i>=s.begin();i++)
       // {
            int i=s.size()-1;
            if(s[i]=='o')
            {
                if(s[i-1]=='o')
                {
                    cout<<"FILIPINO"<<endl;
                  //  break;
                }
            }
            else if(s[i]=='u')
            {
                if(s[i-1]=='s'&&(s[i-2]=='e' ||s[i-2]=='a')&&(s[i-3]=='d'||s[i-3]=='m'))
                {
                    cout<<"JAPANESE"<<endl;
                  //  break;
                }
            }
            else if(s[i]=='a')
            {
                if(s[i-1]=='d'&& s[i-2]=='i'&& s[i-3]=='n'&& s[i-4]=='m')
                {
                    cout<<"KOREAN"<<endl;
                   // break;
                }
            }
       // }
        return 0;

    }
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        char a[4];
        int k=0;
        cin>>s;
       //// for(int i=s.end()-1;i>=s.begin();i++)
       // {
            if(s[i]=='o')
            {
                if(s[i-1]=='o')
                {
                    cout<<"FILIPINO"<<endl;
                   // break;
                }
            }
            else if(s[i]=='u')
            {
                if(s[i-1]=='s'&&(s[i-2]=='e' ||s[i-2]=='a')&&(s[i-3]=='d'||s[i-3]=='m'))
                {
                    cout<<"JAPANESE"<<endl;
                   // break;
                }
            }
            else if(s[i]=='a')
            {
                if(s[i-1]=='d'&& s[i-2]=='i'&& s[i-3]=='n'&& s[i-4]=='m')
                {
                    cout<<"KOREAN"<<endl;
                    //break;
                }
            }
        //}
        return 0;

    }
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s;
       // char a[4];
       // int k=0;
        cin>>s;
       // for(int i=s.end()-1;i>=s.begin();i++)
        {
            int i=s.size()-1;
            if(s[i]=='o')
            {
                if(s[i-1]=='p')
                {
                    cout<<"FILIPINO"<<endl;
                   // break;
                }
            }
            else if(s[i]=='u')
            {
                if(s[i-1]=='s'&&(s[i-2]=='e' ||s[i-2]=='a')&&(s[i-3]=='d'||s[i-3]=='m'))
                {
                    cout<<"JAPANESE"<<endl;
                   // break;
                }
            }
            else if(s[i]=='a')
            {
                if(s[i-1]=='d'&& s[i-2]=='i'&& s[i-3]=='n'&& s[i-4]=='m')
                {
                    cout<<"KOREAN"<<endl;
                    //break;
                }
            }
        }

    }
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        //char a[4];
       // int k=0;
        cin>>s;
        //for(int i=s.end()-1;i>=s.begin();i++)
       // {
            int i=s.size()-1;
            if(s[i]=='o')
            {
                if(s[i-1]=='o')
                {
                    cout<<"FILIPINO"<<endl;
                    break;
                }
            }
            else if(s[i]=='u')
            {
                if(s[i-1]=='s'&&(s[i-2]=='e' ||s[i-2]=='a')&&(s[i-3]=='d'||s[i-3]=='m'))
                {
                    cout<<"JAPANESE"<<endl;
                    break;
                }
            }
            else if(s[i]=='a')
            {
                if(s[i-1]=='d'&& s[i-2]=='i'&& s[i-3]=='n'&& s[i-4]=='m')
                {
                    cout<<"KOREAN"<<endl;
                    break;
                }
            }
       // }
        return 0;

    }
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        char a[4];
        int k=0;
        cin>>s;
        for(int i=s.end()-1;i>=s.begin();i++)
        {
            if(s[i]=='o')
            {
                if(s[i-1]=='o')
                {
                    cout<<"FILIPINO"<<endl;
                    break;
                }
            }
            else if(s[i]=='u')
            {
                if(s[i-1]=='s'&&(s[i-2]=='e' ||s[i-2]=='a')&&(s[i-3]=='d'||s[i-3]=='m'))
                {
                    cout<<"JAPANESE"<<endl;
                    break;
                }
            }
            else if(s[i]=='a')
            {
                if(s[i-1]=='d'&& s[i-2]=='i'&& s[i-3]=='n'&& s[i-4]=='m')
                {
                    cout<<"KOREAN"<<endl;
                    break;
                }
            }
        }
        return 0;

    }
}


#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<set>
#include<utility>
#include<algorithm>
#include<map>

using namespace std;

int n,a[17];

int solve(){
	for(int i=n;i>0;i>>=1){
    	for(int j=0;j<n;j+=i){
    		int flag=1;
    		for(int k=j+1;k<j+i;++k){
    			if(a[k]<a[k-1]){
	    			flag=0;
	    			break;
	    		}
    		}
    		if(flag)return i;
    	}
    }
    return 1;
}

string str;

int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;++i){
    	cin>>str;
    	if(str.substr(str.length()-2)=="po")cout<<"FILIPENO"<<endl;
    	if(str.substr(str.length()-4)=="desu" || str.substr(str.length()-4)=="masu")cout<<"JAPANESE"<<endl;
    	if(str.substr(str.length()-5)=="mnida")cout<<"KOREAN"<<endl;
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<set>
#include<utility>
#include<algorithm>
#include<map>

using namespace std;

int n,a[17];

int solve(){
	for(int i=n;i>0;i>>=1){
    	for(int j=0;j<n;j+=i){
    		int flag=1;
    		for(int k=j+1;k<j+i;++k){
    			if(a[k]<a[k-1]){
	    			flag=0;
	    			break;
	    		}
    		}
    		if(flag)return i;
    	}
    }
    return 1;
}

string str;

int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;++i){
    	cin>>str;
    	if(str.substr(str.length()-2)=="po"){
    		cout<<"FILIPINO"<<endl;
    		continue;
    	}
    	if(str.substr(str.length()-4)=="desu" || str.substr(str.length()-4)=="masu"){
    		cout<<"JAPANESE"<<endl;
    		continue;
    	}
    	if(str.substr(str.length()-5)=="mnida"){
    		cout<<"KOREAN"<<endl;
    		continue;
    	}
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<set>
#include<utility>
#include<algorithm>
#include<map>

using namespace std;

int n,a[17];

int solve(){
	for(int i=n;i>0;i>>=1){
    	for(int j=0;j<n;j+=i){
    		int flag=1;
    		for(int k=j+1;k<j+i;++k){
    			if(a[k]<a[k-1]){
	    			flag=0;
	    			break;
	    		}
    		}
    		if(flag)return i;
    	}
    }
    return 1;
}

string str;

int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;++i){
    	cin>>str;
    	if(str.substr(str.length()-2)=="po")cout<<"FILIPINO"<<endl;
    	if(str.substr(str.length()-4)=="desu" || str.substr(str.length()-4)=="masu")cout<<"JAPANESE"<<endl;
    	if(str.substr(str.length()-5)=="mnida")cout<<"KOREAN"<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;

string detectlang(string sent)
{
	string lang;
	int n;
	n = sent.length();
	sent = sent.substr(n-5);
	if(sent == "mnida")
	{
		lang = "KOREAN";
	}
	else
	{
		sent = sent.substr(1);
		if(sent == "masu" || sent == "desu")
		{
			lang = "JAPANESE";
		}
		else
		{
			lang = "FILIPINO";
		}
	}
	return lang;
}

int main()
{
	string sent;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> sent;
		cout << detectlang(sent) << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;

string detectlang(string sent)
{
	string lang;
	int n;
	n = sent.length();
	if(n == 2 || n == 3)
	{
		lang = "FILIPINO";
	}
	else if (n == 4)
	{
		if (sent.substr(2) == "po")
		{
			lang = "FILIPINO";
		}
		else
		{
			lang = "JAPANESE";
		}
	}
	else
	{
		sent = sent.substr(n-5);
		if(sent == "mnida")
		{
			lang = "KOREAN";
		}
		else
		{
			sent = sent.substr(1);
			if(sent == "masu" || sent == "desu")
			{
				lang = "JAPANESE";
			}
			else
			{
				lang = "FILIPINO";
			}
		}
	}
	return lang;
}

int main()
{
	string sent;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> sent;
		cout << detectlang(sent) << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;

string detectlang(string sent)
{
	string lang;
	int n;
	n = sent.length();
	sent = sent.substr(n-5);
	if(sent == "mnida")
	{
		lang = "KOREAN";
	}
	else
	{
		sent = sent.substr(1);
		if(sent == "masu" || sent == "desu")
		{
			lang = "JAPANESE";
		}
		else
		{
			lang = "FILIPINO";
		}
	}
	return lang;
}

int main()
{
	string sent;
	int n;
	cin >> n;
	for (int i = 0; i < n-1; ++i)
	{
		cin >> sent;
		cout << detectlang(sent) << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;

string detectlang(string sent)
{
	string lang;
	int n;
	n = sent.length();
	sent = sent.substr(n-5);
	if(sent == "mnida")
	{
		lang = "KOREAN";
	}
	else
	{
		sent = sent.substr(1);
		if(sent == "masu" || sent == "desu")
		{
			lang = "JAPANESE";
		}
		else
		{
			lang = "PHILIPINO";
		}
	}
	return lang;
}

int main()
{
	string sent;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> sent;
		cout << detectlang(sent) << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define ne != string::npos
using namespace std;
int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        string s;
        cin >> s;
        string e;
        if (s.size() > 5)
            e = s.substr(s.size()-6, s.size()-1);
        else
            e = s;
        if (e.find("po") ne)
            cout << "FILIPINO";
        else if (e.find("desu") ne || e.find("masu") ne)
            cout << "JAPANESE";
        else if (e.find("mnida") ne)
            cout << "KOREAN";
        cout << endl;
    }
}


#include <bits/stdc++.h>
#define ne != string::npos
using namespace std;
int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        string s;
        cin >> s;
        string e;
        if (s.size() > 5)
            e = s.substr(s.size()-5, s.size());
        else
            e = s;
        cout << e << endl;
        if (e.find("po") ne)
            cout << "FILIPINO";
        else if (e.find("desu") ne || e.find("masu") ne)
            cout << "JAPANESE";
        else if (e.find("mnida") ne)
            cout << "KOREAN";
        cout << endl;
    }
}


#include <bits/stdc++.h>
#define ne != string::npos
using namespace std;
int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        string s;
        cin >> s;
        string e = s.substr(s.size()-6, s.size()-1);
        if (e.find("po") ne)
            cout << "FILIPINO";
        else if (e.find("desu") ne || e.find("masu") ne)
            cout << "JAPANESE";
        else if (e.find("mnida") ne)
            cout << "KOREAN";
        cout << endl;
    }
}


#include <bits/stdc++.h>
#define ne != string::npos
using namespace std;
int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        string s;
        cin >> s;
        string e;
        if (s.size() > 5)
            e = s.substr(s.size()-5, s.size());
        else
            e = s;
        if (e.find("po") ne)
            cout << "FILIPINO";
        else if (e.find("desu") ne || e.find("masu") ne)
            cout << "JAPANESE";
        else if (e.find("mnida") ne)
            cout << "KOREAN";
        cout << endl;
    }
}


#include <bits/stdc++.h>
#define ne != string::npos
using namespace std;
int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        string s;
        cin >> s;
        switch (s[s.size()-1])
        {
        case 'o':
            cout << "FILIPINO";
            break;
        case 'u':
            cout << "JAPANESE";
            break;
        case 'a':
            cout << "KOREAN";
            break;
        }
    }
    cout << endl;
}


#include <bits/stdc++.h>
#define ne != string::npos
using namespace std;
int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        string s;
        cin >> s;
        switch (s[s.size()-1])
        {
        case 'o':
            cout << "FILIPINO";
            break;
        case 'u':
            cout << "JAPANESE";
            break;
        case 'a':
            cout << "KOREAN";
            break;
        }
        cout << endl;
    }
}


#include <iostream>
#include <string>

int main() {
	int c;
	std::cin >> c;

	while(c--) {
		std::string str;
		std::cin >> str;

		for(size_t i(str.size()); i > 0; i--) {
			if(str[i] == 'o' and str[i - 1] == 'p') {
				std::cout << "FILIPINO\n";
			   	break;
			}
			if(str[i] == 'e' and str[i - 1] == 'd') {
				std::cout << "JAPANESE\n";
			   	break;

			}
			if(str[i] == 'a' and str[i - 1] == 'm') {
				std::cout << "JAPANESE\n";
			   	break;
			}
			if(str[i] == 'n' and str[i - 1] == 'm') {
				std::cout << "KOREAN\n";
				break;
			}
		}
	}

	return 0;
}


#include <iostream>
#include <string>

int main() {
	int c;
	std::cin >> c;

	while(c--) {
		std::string str;
		std::cin >> str;

		for(size_t i(str.size()); i > 0; i--) {
			if(str[i] == 'p' and str[i + 1] == 'o') {
				std::cout << "FILIPINO\n";
			   	break;
			}
			if(str[i] == 'd' and str[i + 1] == 'e') {
				std::cout << "JAPANESE\n";
			   	break;

			}
			if(str[i] == 'm' and str[i + 1] == 'a') {
				std::cout << "JAPANESE\n";
			   	break;
			}
			if(str[i] == 'm' and str[i + 1] == 'n') {
				std::cout << "KOREAN\n";
				break;
			}
		}
	}

	return 0;
}


// https://codeforces.com/problemset/problem/1281/A

/* Well, because I'm interested on check the last letters of the string, I start
 * iterating from back to front.
 * Also I see what makes unique the suffices, for Filipino you have a 'p' followed by a 'o'
 * Japanese, 'd' followed by 'e', 'm' followed by a 'a'.
 * Korean, 'm' followed by a 'n'.
 *
 * Having this, is not necessary to check every letter, you only check two letters.
 *
 * But because I'm iterating from back to front, I need to check those letters backwards.
 * Also I have a break because once I check the two letters, I don't want to continue analizing
 * all the string.
 * The str[i - 1] is neccesarry to check the next letter.
 *
 * Example:
 *
 * kamusta_po
 *         ^ ^
 *         | |
 * */

#include <iostream>
#include <string>

int main() {
	int c;
	std::cin >> c;

	while(c--) {
		std::string str;
		std::cin >> str;

		if(str[str.size() - 1] == 'o' and str[str.size() - 2] == 'p') {
			std::cout << "FILIPINO\n";
		}
		if(str[str.size() - 1] == 'u' and str[str.size() - 2] == 's') {
			std::cout << "JAPANESE\n";

		}
		if(str[str.size() - 1] == 'a' and str[str.size() - 2] == 'd') {
			std::cout << "KOREAN\n";
		}
	}

	return 0;
}


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

int main()
{

    int i, j, k;
    int n, m, t;
    string s;

     cin>>t;
     while(t--)
     {

        cin >> s;

        n = s.length();

        if(n >= 2 && s[n - 2] == 'p' && s[n - 1] == 'o')
            cout<<"FILIPINO"<<endl;
        else if(n >= 4 && s[n - 4] == 'd' && s[n - 3] == 'e' && s[n - 2] == 's' && s[n - 1] == 'u')
            cout<<"JAPANESE"<<endl;
        else if(n >= 4 && s[n - 4] == 'm' && s[n - 3] == 'a' && s[n - 2] == 's' && s[n - 1] == 'u')
            cout<<"JAPANESE"<<endl;
        else
            cout<<"KOREAN"<<endl;

     }
    return 0;
}


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

int main()
{

    int i, j, k;
    int n, m, t;
    string s;

     cin>>t;
     while(t--)
     {

        cin >> s;

        n = s.length();

        if(n >= 2 && s[n - 2] == 'p' && s[n - 1] == 'o')
            cout<<"FILIPINO";
        else if(n >= 4 && s[n - 4] == 'd' && s[n - 3] == 'e' && s[n - 2] == 's' && s[n - 1] == 'u')
            cout<<"JAPANESE";
        else if(n >= 4 && s[n - 4] == 'm' && s[n - 3] == 'a' && s[n - 2] == 's' && s[n - 1] == 'u')
            cout<<"JAPANESE";
        else
            cout<<"KOREAN";

     }
    return 0;
}


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

int main()
{

    int i, j, k;
    int n, m, t;
    string s;

    while(cin>>t)
    {
        cin >> s;

        n = s.length();

        if(n >= 2 && s[n - 2] == 'p' && s[n - 1] == 'o')
            cout<<"FILIPINO";
        else if(n >= 4 && s[n - 4] == 'd' && s[n - 3] == 'e' && s[n - 2] == 's' && s[n - 1] == 'u')
            cout<<"JAPANESE";
        else if(n >= 4 && s[n - 4] == 'm' && s[n - 3] == 'a' && s[n - 2] == 's' && s[n - 1] == 'u')
            cout<<"JAPANESE";
        else
            cout<<"KOREAN";

    }

    return 0;
}


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

int main()
{

    int i, j, k;
    int n, m, t;
    string s;

     cin>>t;

        cin >> s;

        n = s.length();

        if(n >= 2 && s[n - 2] == 'p' && s[n - 1] == 'o')
            cout<<"FILIPINO";
        else if(n >= 4 && s[n - 4] == 'd' && s[n - 3] == 'e' && s[n - 2] == 's' && s[n - 1] == 'u')
            cout<<"JAPANESE";
        else if(n >= 4 && s[n - 4] == 'm' && s[n - 3] == 'a' && s[n - 2] == 's' && s[n - 1] == 'u')
            cout<<"JAPANESE";
        else
            cout<<"KOREAN";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int t,k,l;
    cin>>t;
    string s;
    for(k=1;k<=t;k++)
    {
        cin>>s;
        l=s.length();
        if(s[l-2]=='p')
        cout<<"FILIPINO"<<endl;
        else
    {
        if(s[l-5]=='m'&&s[l-4]=='n')
        cout<<"KOREAN"<<endl;
        else
        cout<<"JAPANESE"<<endl;}

    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int t,k,l;
    cin>>t;
    string s;
    for(k=1;k<=t;k++)
    {
        cin>>s;
        l=s.length();
        if(s[l-2]=='p')
        cout<<"FILIPINO"<<endl;
        else if(s[l-5]=='m'&&s[l-4]=='n')
        cout<<"KOREAN"<<endl;
        else if(s[l-4]=='d'&&s[l-4]=='m')
        cout<<"JAPANESE"<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int t,k,l;
    cin>>t;
    string s;
    for(k=1;k<=t;k++)
    {
        cin>>s;
        l=s.length();
        if(s[l-2]=='p')
        cout<<"FILIPINO"<<endl;
        else
    {
        if(s[l-5]=='m'&&s[l-4]=='n')
        cout<<"KOREAN"<<endl;
        else (s[l-4]=='d'&&s[l-4]=='m')
        cout<<"JAPANESE"<<endl;}

    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int t,k,l;
    cin>>t;
    string s;
    for(k=1;k<=t;k++)
    {
        cin>>s;
        l=s.length();
        if(s[l-5]=='m'&&s[l-4]=='n')
        cout<<"KOREAN"<<endl;
        else if((s[l-4]=='d'&&s[l-3]=='e')||(s[l-4]=='m'&&s[l-3]=='a'))
        cout<<"JAPANESE"<<endl;
        else
        cout<<"FILIPINO"<<endl;

    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int t,k,l;
    cin>>t;
    string s;
    for(k=1;k<=t;k++)
    {
        cin>>s;
        l=s.length();
        if(s[l-2]=='p')
        cout<<"FILIPINO"<<endl;
        else if(s[l-5]=='m'&&s[l-4]=='n')
        cout<<"KOREAN"<<endl;
        else if(s[l-4]=='d'&&s[l-4]=='m)
        cout<<"JAPANESE"<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int t,k,l;
    cin>>t;
    string s;
    for(k=1;k<=t;k++)
    {
        cin>>s;
        l=s.length();
        if(s[l-5]=='m'&&s[l-4]=='n')
        cout<<"KOREAN"<<endl;
        else if((s[l-4]=='d'&&s[l-3]=='e')||(s[l-4]=='m'&&s[l-3]=='a'))
        cout<<"JAPANESE"<<endl;
        else
        cout<<"FILIPINO"<<endl;

    }


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int t,k,l;
    cin>>t;
    string s;
    for(k=1;k<=t;k++)
    {
        cin>>s;
        l=s.length();
        if(s[l-6]=='m'&&s[l-5]=='n')
        cout<<"KOREAN"<<endl;
        else if((s[l-5]=='d'&&s[l-4]=='e')||(s[l-5]=='m'&&s[l-4]=='a'))
        cout<<"JAPANESE"<<endl;
        else
        cout<<"FILIPINO"<<endl;

    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,t,n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        string p;
        cin>>p;
        if(p[p.length()-1]=='o' && p[p.length()-2]=='p'){cout<<"FILIPINO"<<endl;
        break;}
        if(p[p.length()-1]=='u' && p[p.length()-2]=='s'){cout<<"JAPANESE"<<endl;
        break;}
        else{
        cout<<"KOREAN"<<endl;}
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,t,n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        string p;
        cin>>p;
        if(p[p.length()-1]=='o' && p[p.length()-2]=='p')cout<<"FILIPINO"<<endl;
        if(p[p.length()-1]=='u' && p[p.length()-2]=='s')cout<<"JAPANESE"<<endl;
        else{
        cout<<"KOREAN"<<endl;}
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,t,n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        string p;
        cin>>p;
        if(p[p.length()-1]=='o' && p[p.length()-2]=='p'){cout<<"FILIPINO"<<endl;
        }
        if(p[p.length()-1]=='u' && p[p.length()-2]=='s'){cout<<"JAPANESE"<<endl;
        }
         if(p[p.length()-1]=='a' && p[p.length()-2]=='d'){cout<<"KOREAN"<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,t,n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        string p;
        cin>>p;
        if(p[p.length()-1]=='o' && p[p.length()-2]=='p')cout<<"FILIPINO";
        if(p[p.length()-1]=='u' && p[p.length()-2]=='s')cout<<"JAPANESE";
        else{
        cout<<"KOREAN";}
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double dbl;
typedef pair<int,int> pii;

#define elif else if
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define faster ios::sync_with_stdio(false); cin.tie(0);
#define fop(i,st,n) for(int i = st; i <= n; i++)
#define fom(i,st,n) for(int i = st; i >= n; i--)

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    for(int i = 1; i <= t; i++){
     	string s;
     	getline(cin,s);
     	if(s.find("po")!=-1){
     		cout << "FILIPINO\n";
     		continue;
     	}
		if(s.find("desu")!=-1 || s.find("masu")!=-1){
		 	cout << "JAPANESE\n";
		 	continue;
		}
		if(s.find("mnida")!=-1){
		 	cout << "KOREAN\n";
		}
    }
	return 0;
}


 #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double dbl;
typedef pair<int,int> pii;

#define elif else if
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define faster ios::sync_with_stdio(false); cin.tie(0);
#define fop(i,st,n) for(int i = st; i <= n; i++)
#define fom(i,st,n) for(int i = st; i >= n; i--)

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    string s;
    getline(cin,s);
    for(int i = 1; i <= t; i++){
     	getline(cin,s);
     	if(s.find("po")!=-1){
     		cout << "FILIPINO\n";
     		continue;
     	}
		if(s.find("desu")!=-1 || s.find("masu")!=-1){
		 	cout << "JAPANESE\n";
		 	continue;
		}
		if(s.find("mnida")!=-1){
		 	cout << "KOREAN\n";
		}
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double dbl;
typedef pair<int,int> pii;

#define elif else if
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define faster ios::sync_with_stdio(false); cin.tie(0);
#define fop(i,st,n) for(int i = st; i <= n; i++)
#define fom(i,st,n) for(int i = st; i >= n; i--)

string s;

void solve_test(){
	getline(cin,s);
	if(s[s.length()-1] == 'o' && s[s.length()-2] == 'p') cout << "FILIPINO\n";
	elif(s[s.length()-1] == 'u' && s[s.length()-2] == 's' && (s[s.length()-3] == 'e' && s[s.length()-4] == 'd' || s[s.length()-3] == 'a' && s[s.length()-4]=='m')){
	 	cout << "JAPANESE\n";
	}
	else
		cout << "KOREAN\n";

}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int t;
    cin >> t;
    getline(cin,s);
    for(int i = 1; i <= t; i++){
		solve_test();
    }

	return 0;
}


 #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double dbl;
typedef pair<int,int> pii;

#define elif else if
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define faster ios::sync_with_stdio(false); cin.tie(0);
#define fop(i,st,n) for(int i = st; i <= n; i++)
#define fom(i,st,n) for(int i = st; i >= n; i--)

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    getline(cin,s);
    for(int i = 1; i <= t; i++){
     	string s;
     	getline(cin,s);
     	if(s.find("po")!=-1){
     		cout << "FILIPINO\n";
     		continue;
     	}
		if(s.find("desu")!=-1 || s.find("masu")!=-1){
		 	cout << "JAPANESE\n";
		 	continue;
		}
		if(s.find("mnida")!=-1){
		 	cout << "KOREAN\n";
		}
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double dbl;
typedef pair<int,int> pii;

#define elif else if
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define faster ios::sync_with_stdio(false); cin.tie(0);
#define fop(i,st,n) for(int i = st; i <= n; i++)
#define fom(i,st,n) for(int i = st; i >= n; i--)

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    for(int i = 1; i <= t; i++){
     	string s;
     	cin >> s;
     	if(s.find("po")!=-1){
     		cout << "FILIPINO\n";
     		continue;
     	}
		if(s.find("desu")!=-1 || s.find("masu")!=-1){
		 	cout << "JAPANESE\n";
		 	continue;
		}
		if(s.find("mnida")!=-1){
		 	cout << "KOREAN\n";
		}
    }
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s[s.length()-1]=='o') cout<<"FILIPINO\n";
        else if(s[s.length()-1]=='u') cout<<"JAPANESE\n";
        else if(s[s.length()-1]=='a') cout<<"KOREAN\n";
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    string s, fil="po", jap="desu", kor="mnida";
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s.find(fil)!= string::npos) cout<<"FILIPINO\n";
        else if(s.find(jap)!= string::npos) cout<<"JAPAN\n";
        else if(s.find(kor)!= string::npos) cout<<"KOREA\n";
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    string s, fil="po", jap="desu", kor="mnida";
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s.find(fil)!= string::npos) cout<<"FILIPINO";
        else if(s.find(jap)!= string::npos) cout<<"JAPAN";
        else if(s.find(kor)!= string::npos) cout<<"KOREA";
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    string s, fil="po", jap1="desu", jap2="masu", kor="mnida";
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s.find(fil)!= string::npos) cout<<"FILIPINO\n";
        else if(s.find(jap1)!= string::npos || s.find(jap2)!= string::npos) cout<<"JAPANESE\n";
        else if(s.find(kor)!= string::npos) cout<<"KOREA\n";
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    string s, fil="po", jap1="desu", jap2="masu", kor="mnida";
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s.find(fil)!= string::npos) cout<<"FILIPINO\n";
        else if(s.find(jap1)!= string::npos && s.find(jap2)!= string::npos) cout<<"JAPANESE\n";
        else if(s.find(kor)!= string::npos) cout<<"KOREA\n";
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    string s, fil="po", jap1="desu", jap2="masu", kor="mnida";
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s.find(fil)!= string::npos) cout<<"FILIPINO\n";
        else if(s.find(jap1)!= string::npos || s.find(jap2)!= string::npos) cout<<"JAPANESE\n";
        else if(s.find(kor)!= string::npos) cout<<"KOREAN\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n;
    cin>>n;
    string f="po",y="desu",y1="masu",k="mnida";
    for(int q=1;q<=n;q++){
        string s;
        cin>>s;
        s=s.substr(s.size()-5,5);
        if(s[s.size()-1]=='o'){
            cout<<"FILIPINO\n";
        }
        else if(s[s.size()-1]=='a'){
            cout<<"KOREAN\n";
        }
        else cout<<"JAPANESE\n";
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n;
    cin>>n;
    string f="po",y="desu",y1="masu",k="mnida";
    for(int q=1;q<=n;q++){
        string s;
        cin>>s;
        s=s.substr(s.size()-5,5);
        for(int i=0;i<s.size();i++){
            if(s.substr(i,k.size())==k&&s.size()-i==k.size()){
                cout<<"KOREAN"<<endl;
            }
            else if(s.substr(i,y.size())==y&&s.size()-i==y.size()){
                cout<<"JAPANESE"<<endl;
            }
            else if(s.substr(i,y1.size())==y1&&s.size()-i==y1.size()){
                cout<<"JAPANESE"<<endl;
            }
            else if(s.substr(i,f.size())==f&&s.size()-i==f.size()){
                cout<<"FILIPINO"<<endl;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     long long int n,l;
     cin>>n;
     string s;
     string s1,s2,s3;
     string p1="po",p2="desu",p22="masu",p3="mnida";
     while(n--)
     {
          cin>>s;
          if(s==p1) cout<<"FILIPINO"<<endl;
          else if(s==p2||s==p22) cout<<"JAPANESE"<<endl;
          else if(s==p3) cout<<"KOREAN"<<endl;
          else
          {
          l=s.size();
          if(p1==s.substr(l-2, l-1)) cout<<"FILIPINO"<<endl;
          else if(p2==s.substr(l-4, l-1) || p22==s.substr(l-4, l-1) ) cout<<"JAPANESE"<<endl;
          else if(p3==s.substr(l-5, l-1)) cout<<"KOREAN"<<endl;
          }
     }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     long long int n,l;
     cin>>n;
     string s;
     string s1,s2,s3;
     string p1="po",p2="desu",p22="masu",p3="mnida";
     while(n--)
     {
          cin>>s;
          l=s.size();
          s1 = s.substr(l-2, l-1);
          s2 = s.substr(l-4, l-1);
          s3 = s.substr(l-5, l-1);
          if(p1==s1) cout<<"FILIPINO"<<endl;
          else if(p2==s2 || p22==s2) cout<<"JAPANESE"<<endl;
          else if(p3==s3) cout<<"KOREAN"<<endl;
     }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     long long int n,l;
     cin>>n;
     string s;
     string s1,s2,s3;
     string p1="po",p2="desu",p22="masu",p3="mnida";
     while(n--)
     {
          cin>>s;
          if(s==p1) cout<<"FILIPINO"<<endl;
          else if(s==p2||s==p22) cout<<"JAPANESE"<<endl;
          else if(s==p3) cout<<"KOREAN"<<endl;
          else
          {
          l=s.size();
          s1 = s.substr(l-2, l-1);
          s2 = s.substr(l-4, l-1);
          s3 = s.substr(l-5, l-1);
          if(p1==s1) cout<<"FILIPINO"<<endl;
          else if(p2==s2 || p22==s2 ) cout<<"JAPANESE"<<endl;
          else if(p3==s3) cout<<"KOREAN"<<endl;
          }
     }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     long long int n,l;
     cin>>n;
     string s;
     string s1,s2,s3;
     string p1="po",p2="desu",p22="masu",p3="mnida";
     while(n--)
     {
          cin>>s;
          l=s.size();
          s1 = s.substr(l-2, l-1);
          s2 = s.substr(l-4, l-1);
          s3 = s.substr(l-5, l-1);
          if(p1==s1) cout<<"FILIPINO"<<endl;
          else if(p2==s2 || p22==s2) cout<<"JAPANESE"<<endl;
          else if(p3==s3) cout<<"KOREAN"<<endl;
     }
     return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        char a[500];
        cin >> a;
        int l = strlen(a);
        if(a[l-1] == 'u')
            cout << "JAPANESE\n";
        else if(a[l-1] == 'a')
            cout << "KOREAN\n";
        else
            cout << "FILIPINO\n";
    }
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        char a[1000];
        scanf("%s", a);
        int l = strlen(a);
        if(a[l-1] == 'u')
            cout << "JAPANESE\n";
        else if(a[l-1] == 'a')
            cout << "KOREAN\n";
        else
            cout << "FILIPINO\n";
    }
}


#include <iostream>
#include <cstring>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        char a[500];
        cin >> a;
        int l = strlen(a);
        if(a[l-1] == 'u')
            cout << "Japnese\n";
        else if(a[l-1] == 'a')
            cout << "Korean\n";
        else
            cout << "Filipino\n";
    }
}


#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        char a[500];
        cin >> a;
        if(a[n-1] == 'u')
            cout << "Japnese\n";
        if(a[n-1] == 'a')
            cout << "Korean\n";
        else
            cout << "Filipino\n";
    }
}


// Не смотри чужой код
#include <bits/stdc++.h>

using namespace std;//

int main() {
  int n;
  scanf("%d", &n);
  vector <int> a(n);
  for (int i = 0; i < n; ++i)
  	scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i)
  	printf("%d ", a[i]);
  return 0;
}


// Не смотри чужой код
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector <int> a(n);
  for (int i = 0; i < n; ++i)
  	scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i)
  	printf("%d ", a[i]);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

main() {
#ifdef OJ
  freopen("input.txt", "r", stdin);
#endif
  int a, b;
  cin >> a >> b;
  cout << a + b;
  return 0;
}


// Не смотри чужой код
#include <bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j)
			cout << i << " " << j << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = (int)(1e6 + 5);

string s[N];

main() {
#ifdef OJ
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  for (int i = 1; i <= n; ++i) {
    if (s[i].back() == 'o') {
      cout << "FILIPINO\n";
    }
    else if (s[i].back == 'u') {
      cout << "JAPANESE\n";
    }
    else {
      cout << "KOREAN\n";
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  cout << "Kanysh Mukhametkarim loh";
}


#include <bits/stdc++.h>

using namespace std;

const int N = (int)(1e6 + 5);

string s[N];

main() {
#ifdef OJ
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  for (int i = 1; i <= n; ++i) {
    if (s[i].back() == 'o') {
      cout << "FILIPINO\n";
    }
    else if (s[i].back() == 'u') {
      cout << "JAPANESE\n";
    }
    else {
      cout << "KOREAN\n";
    }
  }
  return 0;
}


// Не смотри чужой код
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector <int> a(n);
  for (int i = 0; i < n; ++i)
  	scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i)
  	printf("%d ", a[i]);
  return 0;
}
//


#include<bits/stdc++.h>
#define MOD (int)(1e9)
using namespace std;
typedef long long int ll;
string s;
bool ends_with(string k)
{

   return s.rfind(k) == (s.size()-k.size())
; }
int main()
{
        ios_base::sync_with_stdio(false);cin.tie(NULL);
        int t;
        cin>>t;
        while(t--)
        {

            cin>>s;
            reverse(s.begin(),s.end());

            if(  s[0]=='o')

                cout<< "FILIPINO\n";

            else if( s[0]=='u')
              cout<< "JAPANESE\n";
            else cout<< "KOREAN\n";
         //out<<endl;

        }

        return 0;
}


#include<bits/stdc++.h>
#define MOD (int)(1e9)
using namespace std;
typedef long long int ll;
string s;
bool ends_with(string k)
{

   return s.rfind(k) == (s.size()-k.size())
; }
int main()
{
        ios_base::sync_with_stdio(false);cin.tie(NULL);
        int t;
        cin>>t;
        while(t--)
        {

            cin>>s;
            if(ends_with("po"))

                cout<< "FILIPINO\n";

            if(ends_with("masu") || ends_with("desu"))
              cout<< "JAPANESE\n";
            else cout<< "KOREAN\n";
         //out<<endl;

        }

        return 0;
}


#include<bits/stdc++.h>
#define MOD (int)(1e9)
using namespace std;
typedef long long int ll;
string s;
bool ends_with(string k)
{

   return s.rfind(k) == (s.size()-k.size())
; }
int main()
{
        ios_base::sync_with_stdio(false);cin.tie(NULL);
        int t;
        cin>>t;
        while(t--)
        {

            cin>>s;
            reverse(s.begin(),s.end());

            if(  s[0]=='o')

                cout<< "FILIPINO\n";

            if( s[0]=='u')
              cout<< "JAPANESE\n";
            else cout<< "KOREAN\n";
         //out<<endl;

        }

        return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
char ss[N];
char a[3],b[5],c[5];
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%s",ss);
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		int len = strlen(ss);
		int j = 0;
		j = 0;
		for(int i=len-2;i<=len;i++)
			a[j++] = ss[i];
		j = 0;
		for(int i=len-4;i<len;i++)
			b[j++] = ss[i];
		j = 0;
		for(int i=len-5;i<len;i++)
			c[j++] = ss[i];
//		printf("%s___\n",b);
		if( strcmp(a,"po") == 0 )
			printf("%s\n","FILIPINO");
		if( strcmp(b,"desu") == 0 )
			printf("%s\n","JAPANESE");
		if( strcmp(b,"masu") == 0 )
			printf("%s\n","JAPANESE");
		if( strcmp(c,"mnida") == 0 )
			printf("%s\n","KOREAN");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<string,int> mp;
int main()
{
	char s1[10] = "po";
	char s0[10] = "desu";
	char s3[10] = "masu";
	char s2[10] = "mnida";
	int T;
	scanf("%d",&T);
	while(T--)
	{
		string ss;
		cin>>ss;
		char a[10],b[10],c[10];
		int len = ss.length();
		int j = 0;
		for(int i=len-2;i<len;i++)
			a[j++] = ss[i];
		j = 0;
		for(int i=len-4;i<len;i++)
			b[j++] = ss[i];
		j = 0;
		for(int i=len-5;i<len;i++)
			c[j++] = ss[i];
		if( strcmp(a,s1) == 0 )
			printf("%s\n","FILIPINO");
		if( strcmp(b,s0) == 0 || strcmp(b,s3) == 0 )
			printf("%s\n","JAPANESE");
		if( strcmp(c,s2) == 0 )
			printf("%s\n","KOREAN");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
char ss[N];
int main()
{
	char s1[10] = "po";
	char s0[10] = "desu";
	char s3[10] = "masu";
	char s2[10] = "mnida";
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%s",ss);
		char a[10],b[10],c[10];
		int len = strlen(ss);
		int j = 0;
		j = 0;
		for(int i=len-2;i<=len;i++)
			a[j++] = ss[i];
		j = 0;
		for(int i=len-4;i<len;i++)
			b[j++] = ss[i];
		j = 0;
		for(int i=len-5;i<len;i++)
			c[j++] = ss[i];
		if( strcmp(a,s1) == 0 )
			printf("%s\n","FILIPINO");
		if( strcmp(b,s0) == 0 || strcmp(b,s3) == 0 )
			printf("%s\n","JAPANESE");
		if( strcmp(c,s2) == 0 )
			printf("%s\n","KOREAN");
	}
	return 0;
}


#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	 int n,count=0,l;
    string s;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        l=s.size();
        if(s[l-2]=='p' && s[l-1]=='o')
          cout<<"FILIPINO"<<endl;
        else if(s[l-5]=='m' && s[l-4]=='n' && s[l-3]=='i' && s[l-2]=='d')
          cout<<"KOREAN"<<endl;
    else
      cout<<"JAPANESE"<<endl;
    }
    return 0;
}


#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	 int n,count=0,l;
    string s;
    cin>>s;
    l=s.size();
   if(s[l-2]=='p' && s[l-1]=='o')
      cout<<"FILIPINO";
    else if(s[l-5]=='m' && s[l-4]=='n' && s[l-3]=='i' && s[l-2]=='d')
      cout<<"KOREAN";
    else
      cout<<"JAPANESE";
    return 0;
}


#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	 int n,count=0,l;
    string s;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        l=s.size();
        cout<<l;
        if(s[l-2]=='p' && s[l-1]=='o')
          cout<<"FILIPINO";
        else if(s[l-5]=='m' && s[l-4]=='n' && s[l-3]=='i' && s[l-2]=='d')
          cout<<"KOREAN";
    else
      cout<<"JAPANESE";
    }
    return 0;
}