#include <stdio.h>
#include <string.h>

int main(){
    int i, num, flag=0;
    char str[11];
    scanf("%s", str);
    num = strlen(str);
    if(num == 1){
        if(str[0] != '3' || str[0] != '7'){
            printf("No\n");
        }
        else
            printf("Yes\n");
    }
    else{
        for(i=0; i<num/2; i++){
            if(str[i] == '1' || str[i] == '2'){
                printf("No\n");
                flag = 1;
                break;
            }
            if(str[i] == '0'){
                if(str[num-i-1] != '8'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '3'){
                if(str[num-i-1] != '3'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '4'){
                if(str[num-i-1] != '6'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '5'){
                if(str[num-i-1] != '9'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '6'){
                if(str[num-i-1] != '4'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '7'){
                if(str[num-i-1] != '7'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '8'){
                if(str[num-i-1] != '0'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
            if(str[i] == '9'){
                if(str[num-i-1] != '5'){
                    printf("No\n");
                    flag = 1;
                    break;
                }
            }
        }
        if(num%2 == 1 && flag == 0){
            if(str[num/2] == '0' || str[num/2] == '1' || str[num/2] == '2' || str[num/2] == '4' || str[num/2] == '5' || str[num/2] == '6' || str[num/2] == '8' || str[num/2] == '9'){
                printf("No\n");
                flag = 1;
            }
        }
        if(flag == 0){
            printf("Yes\n");
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdbool.h>
#include <string.h>

bool braille(char *a, int len)
{
    if(len == 1)
    {
        if(a[0] == '3' || a[0] == '7')
            return true;
        else
            return false;
    }

	int i = 0;
	int n = len - 1;

	while(i < n)
	{
        int old_i = i;

        if((a[i] == '4' || a[i] == '6') && (a[i] == '6' || a[i] == '4'))
            i++;

        else if((a[i] == '5' || a[i] == '9') && (a[i] == '9' || a[i] == '5'))
            i++;

        else if((a[i] == '8' || a[i] == '0') && (a[i] == '0' || a[i] == '8'))
            i++;

        else if(a[i] == '3' && a[n] == '3')
            i++;

        else if(a[i] == '7' && a[n] == '7')
            i++;

        if(i == old_i)
            return false;
        else
            n--;
    }

    if(a[i] == '1' || a[i] == '2')
        return false;
    else
        return true;
}

int main()
{
    char num[10];
    scanf("%s", num);

    braille(num, strlen(num))? printf("Yes\n") : printf("No\n");

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmp(const void *a,const void *b) {
	return strcmp(*(char **)a,*(char **)b);
}

int main() {
	char s[101];
	scanf("%s\n",s);
	int i,m,l=strlen(s);
	char *x[l],*p,*q;
	p=s;
	while (*p) {
		x[p-s]=p;
		p++;
	}
	qsort(x,l+1,sizeof *x,cmp);
	m=0;
	for (i=1;i<l;i++) {
		for (p=x[i],q=x[i-1];*p==*q;p++,q++) ;
		if (p-x[i]>m) m=p-x[i];
	}
	printf("%d\n",m);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>

int main () {

    uint64_t n;
    scanf("%"SCNu64, &n);

    if (n % 2 == 0) {
        printf("%"PRIu64i"\n", n / 2);
    }
    else {
        uint64_t j = 3;
        for ( ; j * j <= n; j += 2) {
            if (n % j == 0) {
                printf("%"PRIu64"\n", (1 + (n - j) / 2));
                n = 1;
                break;
            }
        }
        if (n > 1) {
            putchar('1');
            putchar("\n");
        }
    }

    return 0;
}
~
~


#include<stdio.h>
int main()
{
    long long int n,n1,i,j=2,flag=0,a[10000];

    scanf("%lld",&n);

    a[0]=2;

    long long int count=0;

    while(1){
        if(n%2!=0){
            for(i=2;i<=n;i++){
                flag=0;
                for(j=2;j<=i/2;j++){
                    if(i%j==0){
                        flag=1;
                        break;
                    }
                }

                if(flag==0){
                    if(n%i==0){
                        n1=n-i;
                        break;
                    }
                }
            }

            count=(n1/2)+1;
            n=0;
        }
        else if(n%2==0){
            count=n/2;
            n=0;
        }

        if(n==0) break;
    }
    printf("%lld",count);

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,a,b;
    scanf("%d",&n);
    printf("%d %d",n/36,n%36/3)
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{

	int n;
	int feet;
	int inch;

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

		scanf("%d", &n);

		feet = n / 36;
		inch = n % 36;

		inch = (inch + 1 )/3;

		if (inch == 12)
		{
			feet++;
			inch = 0;
		}
		printf("%d %d\n", foot, inch);

	return 0;
}


#include <stdio.h>
using namespace std;

main() {
    int h, m, a;
    scanf("%d:%d%d", &h, &m, &a);
    m += a; h += m / 60; m %= 60; h %= 24;
    if (h < 10) printf("0");printf("%d:", h);
    if (m < 10) printf("0");printf("%d ", m);
}


#include<stdlib.h>
#include<stdio.h>
#include<string.h>

typedef long long int lli;

#define TRUE         (1==1)
#define FALSE        (!(TRUE))
#define in32(x)      scanf("%d", &(x))
#define in64(x)      scanf("%I64d", &(x))
#define instr(x)     scanf("%s", (x))
#define out32(x)     printf("%d\n", (x))
#define out64(x)     printf("%I64d\n", (x))
#define outstr(x)    printf("%s\n", (x))
#define max(a,b)     ((a)<(b))?(b):(a)
#define min(a,b)     ((a)>(b))?(b):(a)
#define abs(a)       ((a)<0)?(-(a)):(a)
#define fo3(i,a,b)   for(i=(int)(a);i<=(int)(b);i++)
#define of3(i,a,b)   for(i=(int)(a);i>=(int)(b);i--)

#define MOD    998244353
#define MAX    5005
#define SENT   -1

typedef struct Pair {
    int fi, se;
} Pair;

int comp(Pair * f, Pair * s) {
    return (f->fi - s->fi);
}

void sort(Pair ** arr, int size) { // CHANGE THIS
    int i;
    if (size < 6) {
        int nSize = 0;
        int s = size;
        while (size != 0) {
            nSize = 0;
            for (i = 0; i < size - 1; i++)
                if (comp(arr[i], arr[i+1]) > 0) { // CHANGE THIS
                    Pair * tmp = arr[i];
                    arr[i] = arr[i+1];
                    arr[i+1] = tmp;
                    nSize = i+1;
                }
            size = nSize;
        }
        return;
    }
    Pair ** tmp = (Pair **)calloc(size, sizeof(Pair *)); // CHANGE THIS
    int lSize = (size >> 1);
    int rSize = size - lSize;
    sort(arr, lSize); sort(arr + lSize, rSize);
    int lPtr = 0, rPtr = 0;
    int ptr = 0;
    while (ptr != size) {
        if (lPtr == lSize)
            tmp[ptr] = arr[lSize + (rPtr++)];
        else if (rPtr == rSize || comp(arr[lPtr], arr[lSize + rPtr]) <= 0) // CHANGE THIS
            tmp[ptr] = arr[lPtr++];
        else
            tmp[ptr] = arr[lSize + (rPtr++)];
        ptr++;
    }
    for (i = 0; i < size; i++)
        arr[i] = tmp[i];
    free(tmp);
}

int main(void) {
    int i, n, m;
    in32(n);
    in32(m);
    int need[n];
    fo3(i,0,n-1)
        in32(need[i]);
    Pair ** p = calloc(m, sizeof(Pair*));
    fo3(i,0,m-1) {
        p[i] = calloc(1,sizeof(Pair));
        in32(p[i]->fi);
        in32(p[i]->se);
    }
    sort(p,m);
    lli pos = 2000000, min = 0, max = 2000000 - 1;
    int have[n];
    while (min <= max) {
        lli mid = (min + max) >> 1;
        fo3(i,0,n-1)
            have[i] = 0;
        lli spent = 0;
        lli maxDay = mid;
        of3(i,m-1,0) {
            int day = p[i]->fi;
            int ind = p[i]->se-1;
            int miss = need[ind] - have[ind];
            if (maxDay > day)
                maxDay = day;
            int buy = miss;
            if (buy > maxDay)
                buy = maxDay;
            have[ind] += buy;
            maxDay -= buy;
            spent += buy;
        }
        fo3(i,0,n-1)
            spent += ((need[i] - have[i])<<1);
        if (spent <= mid) {
            pos = mid;
            max = mid - 1;
        } else
            min = mid + 1;
    }
    out64(pos);
    return 0;
}


#include <stdio.h>

typedef struct mk
{
	int day,type;
}roy;

int n,m,a[200010],l,r,tot=0;
roy off[200010],tmp[200020];

int ok(int days){
	int t[n+1];
	int need = 0,collect = 0;
	for(int i = 0;i<n;i++) t[i] = a[i];
	for(int i = 0;i<m;i++){
		if(i==0) collect = off[i].day;
		else collect += (off[i].day - off[i-1].day);
		if(t[off[i].type-1] && collect){
			int tp = (collect<=t[off[i].type-1])?collect:t[off[i].type-1];
			need += tp;
			t[off[i].type-1]-= tp;
			collect-=tp;
		}

	}
	need += (tot - need)*2;
	return (need<=days);
}
void merge(roy *of, int s,int m,int e){
	int i = s,j = m+1,k = 0;
	while (i<=m && j<=e){
		if(of[i].day==of[j].day){
			tmp[k++] = (a[of[i].type-1]<a[of[j].type-1])?of[i++]:of[j++];
		}
		else tmp[k++] = (of[i].day<of[j].day)?of[i++]:of[j++];
	}
	while (i<=m) tmp[k++] = of[i++];
	while (j<=e) tmp[k++] = of[j++];
	for(int i = s;i<=e;i++) {
		of[i] = tmp[i-s];
	}
}
void sort(roy *of, int s,int e){
	if(s<e){
		int m = (e+s)/2;
		sort(of,s,m);
		sort(of,m+1,e);
		merge(of,s,m,e);
	}
}
void solve(){
	scanf("%d%d",&n,&m);
	for(int i = 0;i<n;i++){
		scanf("%d",a+i);
		tot += a[i];
	}
	for(int i = 0;i<m;i++){
		scanf("%d%d",&off[i].day,&off[i].type);
	}
	sort(off, 0, m-1);
	l = 1;r = tot*2+1;
	int Ans;
	while (l<=r)
	{
		int m = (l+r)/2;
		if(ok(m)){
			Ans  = m;
			r = m-1;
		}
		else l = m+1;
	}
	for(int i = l;i<=r;i++){
		if(ok(i)){
			Ans = i;
			break;
		}
	}
	printf("%d\n",Ans);
}
int main(){
	solve();
	return 0;
}


#include<stdio.h>

int main()
{
    int n,i;
    scanf("%d",&n);
    int arr[n/2];
    for(i=0;i<n/2;i++)
    {
        scanf("%d",&arr[i]);
    }
    int count=n,yes=n-1,temp,count1=0,count2=0;
        for(i=n/2-1;i>=0;i--)
        {
            temp=arr[i];
            while(temp!=count)
            {
                if(temp>count)
                {
                    arr[i]--;
                    count1++;
                }
                else
                {
                    temp++;
                    count1++;
                }
            }
            count-=2;

        }
         for(i=n/2-1;i>=0;i--)
        {
            temp=arr[i];
            while(temp!=yes)
            {
                if(temp>yes)
                {
                    temp--;
                    count2++;
                }
                else
                {
                    temp++;
                    count2++;
                }
            }
            yes-=2;

        }
        count1<count2?printf("%d",count1):printf("%d",count2);
        return 0;
}


/* main.c */

// D <--~~~  __      _
// U       o'')}____//
// O       `_/      )
// N       (_(_/-(_/
// G ~~~~~~~~~~~~~~~~~-->

#include <stdio.h>
#include <stdlib.h>

#define loop(i, a, b) for(int i=a; i<b; i++)

typedef long long ll;

const ll MOD_PRIME = 10e9 + 7;

void solve(){
    ll n, S;
    scanf("%ld", &n);
    ll* dp = calloc(n+1, sizeof(ll));
    loop(i, 1, n+1){
        loop(j, i+i, n+1){
            dp[j]++;
        }
    }
    dp[0] = S = 1;
    loop(i, 1, n+1){
        dp[i] += S;
        S += dp[i];
        dp[i] %= 998244353;
    }
    printf("%d", dp[n]);
    return;
}

int main(void){
    int T=1;
    //scanf("%d", &T);
    loop(t, 0, T){
        solve();
    }
    return 0;
}


/* main.c */

// D <--~~~  __      _
// U       o'')}____//
// O       `_/      )
// N       (_(_/-(_/
// G ~~~~~~~~~~~~~~~~~-->

#include <stdio.h>
#include <stdlib.h>

#define loop(i, a, b) for(ll i=a; i<b; i++)

typedef long long ll;

const ll MOD_PRIME = 10e9 + 7;

void solve(){
    ll n, S;
    scanf("%lld", &n);
    ll* dp = calloc(n+1, sizeof(ll));
    loop(i, 1, n+1){
        for(int j=i+i; j<n+1; j+=i){
            dp[j]++;
        }
    }
    dp[0] = S = 1;
    loop(i, 1, n+1){
        dp[i] += S;
        S += dp[i];
        dp[i] %= 998244353;
    }
    printf("%lld", dp[n]);
    return;
}

int main(void){
    int T=1;
    //scanf("%d", &T);
    loop(t, 0, T){
        solve();
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#define psum(arr, i) ((i)<0?0:(arr[i]))
#define uint unsigned int

int main()
{
        int n, mod; scanf("%d %d", &n, &mod);

        int* dp = malloc(n*sizeof(int));
        int* dpsum = calloc(n*sizeof(int), 1);

        dp[0] = 1;
        dpsum[0] = 1;

        printf("1\n");
        for (int i=1; i<n; i++) {
                dp[i] = dpsum[i-1];

                int rind=n-i;
                for (int z=2; n>=rind*z; z++) {
                        dp[i] += (dpsum[n-(rind*z)] - psum(dpsum, n-(rind*z+z)) + mod) % mod;
                        dp[i] %= mod;
                        // printf("adding range from %d to %d\n", n-rind*z, n-rind*z-z);
                }

                // printf("%d\n", dp[i]);
                dpsum[i] = dp[i] + dpsum[i-1];
                dpsum[i] %= mod;
        }
        printf("%d\n", dp[n-1]);
        free(dp); free(dpsum);
}


#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define cL while (getchar() != '\n')  //clear line
#define fi(x) for (i = 0; i < x; i++)
#define fj(x) for (j = 0; j < x; j++)
#define FOR(a, b, c) for (int(a) = (b); (b) < (c) ? (a) <= (c) : (a) >= (c); (b) < (c) ? (a)++ : (a)--)
#define LL long long
#define min(a, b) (a > b ? b : a)
#define max(a, b) (a < b ? b : a)
#define pf printf
#define sf scanf

int main() {
    LL i, j;
    scanf("%lld%lld", &i, &j);
    char a[2000], b[2000];
    memset(b, 0, sizeof(b));
    memset(a, 0, sizeof(a));
    LL p1 = 0, p2 = 0, k = 0, a1 = i, a2 = j;
    if (i == j) {
        printf("YES");
        return 0;
    }
    if (i == 0) {
        printf("NO");
        return 0;
    }
    while (i) {
        a[++p1] = i % 2 + 97, k -= i % 2;
        i /= 2;
    }
    while (j) {
        b[++p2] = j % 2 + 97, k += j % 2;
        j /= 2;
    }
    int k1 = strstr(b+1, a+1);
    if (k1) {
        if (p2 - p1 == k) {
            printf("YES");
            return 0;
        }
    }
    FOR(i, 1, p1 / 2) {
        char tmp;
        tmp = a[i], a[i] = a[p1 + 1 - i], a[p1 + 1 - i] = tmp;
    }
    k1 = strstr(b+1, a+1);
    if (k1) {
        if (p2 - p1 == k) {
            printf("YES");
            return 0;
        }
    }

    p1 = 0, p2 = 0, k = 0;
    i = a1, j = a2;
    memset(b, 0, sizeof(b));
    memset(a, 0, sizeof(a));

    while (i % 2 == 0)
        i /= 2;
    while (i) {
        a[++p1] = i % 2 + 97, k -= i % 2;
        i /= 2;
    }
    while (j) {
        b[++p2] = j % 2 + 97, k += j % 2;
        j /= 2;
    }
    k1 = strstr(b+1, a+1);
    if (k1) {
        if (p2 - p1 == k) {
            printf("YES");
            return 0;
        }
    }
    FOR(i, 1, p1 / 2) {
        char tmp;
        tmp = a[i], a[i] = a[p1 + 1 - i], a[p1 + 1 - i] = tmp;
    }
    k1 = strstr(b+1, a+1);
    if (k1) {
        if (p2 - p1 == k) {
            printf("YES");
            return 0;
        }
    }
    printf("NO");
    return 0;
}


#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int count(long long a) {
  int n = 0;
  while (a) {
    n += !!(a&1);
    a >>= 1;
  }
  return n;
}

char *gen(long long a) {
  char *perm = malloc(sizeof(char) * count(a));
  int i = 0;
  perm[i] = '0';
  while (a) {
    if (a & 1) perm[++i] = '0';
    else perm[i]++;
    a >>= 1;
  }
  perm[i] = '\0';
  return perm;
}

char *reverse(char *px) {
  char *perm = malloc(sizeof(char) * px[0]);
  int n = strlen(px);
  for (int i = 0; i < n; i++)
    perm[i] = px[n-1-i];
  perm[n] = '\0';
  return perm;
}

int check(char *y, char *x) {
  char *str = strstr(y, x);
  if (str == NULL) return 0;
  char a[28] = "000000000000000000000000000", temp[27];
  int len = strlen(x);
  strncpy(temp, str, len);
  strncpy(str, a, len);
  for (int i = 0; y[i] != '\0'; i++)
    if (y[i] != '0' && y[i] != '1') return 0;

  strncpy(str, temp, len);
  return 1;
}

int main() {
  long long x, y;
  scanf("%"PRId64"%"PRId64"", &x, &y);
  char *permX = gen(x), *permY = gen(y);
  int found = check(permY, permX);
  found |= check(permY, permX+1);
  permX = reverse(permX);
  found |= check(permY, permX);
  puts(found ? "YES" : "NO");

  return 0;
}


#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *reverse(char *px) {
  int n = strlen(px);
  char *perm = malloc(sizeof(char) * (n+1));
  for (int i = 0; i < n; i++)
    perm[i] = px[n-1-i];
  perm[n] = '\0';
  return perm;
}

char *gen(long long a) {
  char *perm = malloc(sizeof(char) * 100);
  int i = 0;
  while (a) {
    if (a & 1) perm[i++] = '1';
    else perm[i++] = '0';
    a >>= 1;
  }
  perm[i] = '\0';
  return reverse(perm);
}

int check(char *y, char *x) {
  char *yy = malloc(sizeof(char) * 100), *xx = malloc(sizeof(char) * 100), one[100], temp[100];
  strcpy(xx, x), strcpy(yy, y);
  for (int i = 0; i < 100; i++) one[i] = '1';

  char *str = strstr(yy, xx);
  int len = strlen(xx), i;
  if (str != NULL) {
    strncpy(temp, str, len);
    strncpy(str, one, len);
    for (i = 0; yy[i] != '\0'; i++)
      if (yy[i] != '1') break;
    strncpy(str, temp, len);

    if (yy[i] == '\0') return 1;
  }

  xx = reverse(xx);

  str = strstr(yy, xx);
  if (str != NULL) {
    strncpy(temp, str, len);
    strncpy(str, one, len);
    for (i = 0; yy[i] != '\0'; i++)
      if (yy[i] != '1') break;
    strncpy(str, temp, len);

    if (yy[i] == '\0') return 1;
  }

  return 0;
}

int main() {
  long long x, y;
  scanf("%"PRId64"%"PRId64"", &x, &y);
  char *permX = gen(x), *permY = gen(y);
  x = strlen(permX), y = strlen(permY);

  int found = 0;
  if (permX[x-1] == '1') {
    found |= check(permY, permX);
  }
  else {
    permX[x] = '1', permX[x+1] = '\0';
    found |= check(permY, permX);
    while (permX[x-1] == '0') permX[--x] = '\0';
    found |= check(permY, permX);
  }

  puts(found ? "YES" : "NO");

  return 0;
}


#define __USE_MINGW_ANSI_STDIO 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define maxN 65

char str[maxN];
char tmpstr[maxN];
char tgt[maxN];

int zeroCnt(char *str) {
    int ctr = 0;
    for (int i = strlen(str) - 1; i >= 0; --i) {
        if (str[i] == '0') ++ctr;
    }
    return ctr;
}

void trim(char *str) {
    for (int i = strlen(str) - 1; i >= 0; --i) {
        if (str[i] == '1') break;
        else str[i] = '\0';
    }
}

static inline void cswap(char *a, char *b) {
    char tmp = *a;
    *a = *b;
    *b = tmp;
    return;
}

void reverse(char *str) {
    int p = 0, q = strlen(str) - 1;
    for (; p < q; ++p, --q) {
        cswap(&str[p], &str[q]);
    }
}

// bin
#define lltoa(a, b) _lltoa(a, b)
void _lltoa(long long num, char *dest) {
    int len = 0;
    while (num) {
        if (num % 2 == 0) dest[len++] = '0';
        else dest[len++] = '1';
        num /= 2;
    }
    dest[len] = '\0';
    reverse(dest);
}

void testcase() {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    lltoa(a, str);
    lltoa(b, tgt);
    // Orig string: Either equal, or at least a 1 on the right, and any amount of 1s on the left and right after.
    if (strcmp(tgt, str) == 0) { printf("YES\n"); return; }
    // Make sure at least one 1 is on the right.
    strcpy(tmpstr, str);
    int len = strlen(tmpstr);
    if (tmpstr[len - 1] == '0') {
        tmpstr[len++] = '1';
        tmpstr[len] = '\0';
    }
    if (strstr(tgt, tmpstr) && zeroCnt(tgt) == zeroCnt(tmpstr)) { printf("YES\n"); return; }

    // 2 flips performed: Completely trimmed. Add any amount of 1s to the left or right.
    trim(str);
    if (strstr(tgt, str) && zeroCnt(tgt) == zeroCnt(str)) { printf("YES\n"); return; }

    // 1 flip performed. Both sides start and end with a 1. Add any amounts of 1 left and right.
    reverse(str);
    trim(str);
    if (strstr(tgt, str) && zeroCnt(tgt) == zeroCnt(str)) { printf("YES\n"); return; }
    printf("NO\n");

    return;
}

int main() {
    testcase();
    return 0;
}


#include <stdio.h>

#define N	62

long long min(long long a, long long b) { return a < b ? a : b; }

long long rev(long long x) {
	long long y = 0;

	while (x) {
		y = y << 1 | (x & 1);
		x >>= 1;
	}
	return y;
}

long long padded(long long a, long long b) {
	return a % b == 0 && ((a / b) & (a / b - 1)) == 0;
}

int main() {
	static long long yy[N];
	long long x, y, z;
	int n, l, r, i;

	scanf("%lld%lld", &x, &y), x = rev(rev(x));
	if (x == y) {
		printf("YES\n");
		return 0;
	}
	if ((y & 1) == 0) {
		printf("NO\n");
		return 0;
	}
	n = 0;
	while (y)
		yy[n++] = y & 1, y >>= 1;
	for (l = 0; l < n; l++) {
		for (r = n - 1; r >= 0; r--) {
			if (yy[l] == 0 && yy[r] == 0)
				break;
			else if (yy[l] == 0) {
				z = 0;
				for (i = r; i >= l; i--)
					z = z * 2 + yy[i];
				if (x == z) {
					printf("YES\n");
					return 0;
				}
			} else if (yy[r] == 0) {
				z = 0;
				for (i = l; i <= r; i++)
					z = z * 2 + yy[i];
				if (x == z) {
					printf("YES\n");
					return 0;
				}
				break;
			} else {
				z = 0;
				for (i = l; i <= r; i++)
					z = z * 2 + yy[i];
				if (padded(x, z) || padded(x, rev(z))) {
					printf("YES\n");
					return 0;
				}
			}
		}
		if (yy[l] == 0)
			break;
	}
	printf("NO\n");
	return 0;
}


#include <stdio.h>

#define N	62

long long min(long long a, long long b) { return a < b ? a : b; }

long long rev(long long x) {
	long long y = 0;

	while (x) {
		y = y << 1 | (x & 1);
		x >>= 1;
	}
	return y;
}

long long padded(long long a, long long b) {
	return a % b == 0 && ((a / b) & (a / b - 1)) == 0;
}

int main() {
	static long long yy[N];
	long long x, y, z;
	int n, l, r, i;

	scanf("%lld%lld", &x, &y);
	if (x == y) {
		printf("YES\n");
		return 0;
	}
	if ((y & 1) == 0) {
		printf("NO\n");
		return 0;
	}
	n = 0;
	while (y)
		yy[n++] = y & 1, y >>= 1;
	for (l = 0; l < n; l++) {
		for (r = n - 1; r >= 0; r--) {
			if (yy[l] == 0 && yy[r] == 0)
				break;
			else if (yy[l] == 0) {
				z = 0;
				for (i = r; i >= l; i--)
					z = z * 2 + yy[i];
				if (x == z) {
					printf("YES\n");
					return 0;
				}
			} else if (yy[r] == 0) {
				z = 0;
				for (i = l; i <= r; i++)
					z = z * 2 + yy[i];
				if (x == z) {
					printf("YES\n");
					return 0;
				}
				break;
			} else {
				z = 0;
				for (i = l; i <= r; i++)
					z = z * 2 + yy[i];
				if (padded(x, z) || padded(x, rev(z))) {
					printf("YES\n");
					return 0;
				}
			}
		}
		if (yy[l] == 0)
			break;
	}
	printf("NO\n");
	return 0;
}


#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

int64_t x, y;
int n_0, n_1, m;
int s_0[100], s_1[100], t[100];

void build(int64_t value, int* buffer, int* size, bool keep_trailing_zero) {
    *size = 0;
    if (!keep_trailing_zero)
        while (value % 2 == 0) value /= 2;
    while (value > 0) {
        buffer[(*size)++] = value % 2;
        value /= 2;
    }
}

void reverse(int* a, int size) {
    for (int i = 0, j = size - 1; i < j; i++, j--) {
        a[i] ^= a[j];
        a[j] ^= a[i];
        a[i] ^= a[j];
    }
}

bool try_match(int* s, int n, int* t, int m) {
    for (int i = 0; i + n <= m; i++) {
        if (t[i] == 0) break;
        bool good = true;
        for (int j = 0; j < n; j++) {
            if (t[i + j] != s[j]) {
                good = false;
                break;
            }
        }
        if (!good) continue;
        for (int j = i + n; j < m; j++) {
            if (t[j] == 0) {
                good = false;
                break;
            }
        }
        if (good) return true;
    }
    return false;
}

void solve() {
    scanf("%lld %lld", &x, &y);
    build(x, s_0, &n_0, false);
    build(x * 2 + 1, s_1, &n_1, true);
    build(y, t, &m, true);
    if (try_match(s_0, n_0, t, m)) {
        printf("YES\n");
        return;
    }
    reverse(s_0, n_0);
    if (try_match(s_0, n_0, t, m)) {
        printf("YES\n");
        return;
    }

    if (try_match(s_1, n_1, t, m)) {
        printf("YES\n");
        return;
    }
    reverse(s_1, n_1);
    if (try_match(s_1, n_1, t, m)) {
        printf("YES\n");
        return;
    }

    printf("NO\n");
}

int main() {
    int t = 1;
    // scanf("%d", &t);
    while (t--) solve();
}


#include <stdio.h>

int func (long long x, int n, int ans, int num, long long *pow10, long long *pow9) {
  int cnt = 0;
  int digit[10] = {};

  long long tmp = x;

  while (tmp > 0LL) {
    digit[(int)(tmp%10LL)] = 1;
    tmp /= 10LL;
    cnt++;
  }

  if (cnt > n) {
    return 100;
  }

  if (cnt == n) {
    return num;
  }

  for (int i = 9; i > 1; i--) {
    if (digit[i] > 0) {
      long long nx = x*((long long)i);
      if (ans-num-1 > 17 || (pow10[n-1]-1LL)/pow9[ans-num-1] < nx) {
        int tmp = func(nx, n, ans, num+1, pow10, pow9);
        if (tmp < ans) {
          ans = tmp;
        }
      }
    }
  }

  return ans;
}

int main () {
  int n = 0;
  long long x = 0LL;

  int res = 0;

  long long pow10[19] = {};
  long long pow9[19] = {};

  int ans = 0;

  res = scanf("%d", &n);
  res = scanf("%lld", &x);

  pow10[0] = 1LL;
  for (int i = 1; i <= n; i++) {
    pow10[i] = 10LL*pow10[i-1];
  }

  pow9[0] = 1LL;
  for (int i = 1; i < 19; i++) {
    pow9[i] = 9LL*pow9[i-1];
  }

  ans = func(x, n, 100, 0, pow10, pow9);
  if (ans >= 100) {
    ans = -1;
  }

  printf("%d\n", ans);

  return 0;
}


#include <stdio.h>

typedef unsigned long long ll;
#define rll register ll
#define rint register int
#define rep(i,a,b) for(rint i=(a);i<(b);i++)
#define repe(i,a,b) for(rint i=(a);i<=(b);i++)
#define repr(i,a,b) for(rint i=(a)-1;(b)<=i;i--)

int writeBuffer[20];
void write(ll num) { if (num == 0) putchar('0'); else { rint size = 0; rll current; if (0 < num) current = num; else current = -num, putchar('-'); while (0 < current) writeBuffer[size++] = current%10+'0', current /= 10; while (0 < size) putchar(writeBuffer[--size]); } }
ll read() { rint sign = 1; rll num = 0; while (1) { rint ch = getchar(); if (ch == '-') { sign = -sign; continue; } if (ch <= 32) break; num = num*10+(ch-'0'); } return sign*num; }

ll dp[100][1<<10];

int main() {
    rint n = read();
    rll target = 1;
    rep(i,0,n) target *= 10;

    rll x = read();

    {
        rint mask = 0;
        for (rll temp=x;temp;temp/=10) mask |= 1<<(temp%10);
        dp[0][mask] = x;
    }

    rint depth = 0;
    while (1) {
        rint found = 0;
        rep(j,0,1024) {
            rll num = dp[depth][j];
            if (num) {
                rep(k,2,10) if (j&(1<<k)) {
                    rll newNum = num*k;
                    if (target <= newNum) {
                        write(depth), putchar('\n');
                        return 0;
                    }
                    found = 1;
                    rint mask = 0;
                    for (rll temp=newNum;temp;temp/=10) mask |= 1<<(temp%10);
                    if (dp[depth+1][mask] < newNum) dp[depth+1][mask] = newNum;
                }
            }
        }
        if (!found) {
            putchar('-'), putchar('1'), putchar('\n');
            return 0;
        }
        depth++;
    }
}


//C n+m-1 m;
//2^(y-1);

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
using namespace std;
vector<int>v[1000500];
const int mod=1000000007;
int cur[1000500];
long long inv[2000050];
long long fc[2000050];
long long vv[1000500];
long long f(long long a,long long b);
void init()
{
	memset(cur,0,sizeof(cur));
	fc[0]=1LL;
	for(int i=1;i<2000000;i++)
	fc[i]=fc[i-1]*i%mod;
	for(int i=0;i<2000000;i++)
	inv[i]=f(fc[i],mod-2);
	for(int i=1;i<=1000000;i++)
	vv[i]=i;
	cur[1]=1;
	for(int i=2;i<=1000000;i++)
	{
		if(!cur[i])
		{
			v[i].push_back(1);
			for(int j=i+i;j<=1000000;j+=i)
			{
				cur[j]=1;
				int q=0;
				while(vv[j]%i==0)
				{
					q++;
					vv[j]/=i;
				}
				v[j].push_back(q);
			}
		}
	}
}
long long f(long long a,long long b)
{
	long long c=1;
	while(b)
	{
		if(b&1)
		{
			c*=a;
			c%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return c;
}
int main()
{

	init();
	int T;
	scanf("%d",&T);
	while(T--)
	{
		long long x,y;
		scanf("%lld%lld",&x,&y);
		long long ans=1;
		for(int i=0;i<v[x].size();i++)
		{
			int q=v[x][i];
			ans=ans*fc[q+y-1]%mod*inv[q]%mod*inv[y-1]%mod;
		}
		//printf("!! %lld\n",ans);
		//printf("~~ %lld\n",f(2,y-1));
		ans*=f(2,y-1);
		ans%=mod;
		printf("%lld\n",ans);
	}
}


#include<stdio.h>
int main(){
    int n,k;
    // int sum=0;
    int arr[3];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int p;
        scanf("%d",&p);
        for (int j=0;j<3;j++){
            scanf("%d",&k);
            arr[j]=k;
        }
        if(arr[p-1]==0){
            printf("NO\n");
        } else if(arr[arr[p-1]-1]>0){
            printf("YES\n");
        }else printf("NO");
    }
    return 0;
}


#include<stdio.h>
int main(){
    int n,k;
    // int sum=0;
    int arr[3];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int p;
        scanf("%d",&p);
        for (int j=0;j<p;j++){
            scanf("%d",&k);
            arr[j]=k;
        }
        if(arr[p-1]==0){
            printf("NO\n");
        } else (arr[arr[p-1]]>0&&arr[arr[arr[p-1]]]>0){
            printf("YES\n");
        }
    }
    return 0;
}


#include<stdio.h>
int main(){
    int n,k;
    // int sum=0;
    int arr[3];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int p;
        scanf("%d",&p);
        for (int j=0;j<p;j++){
            scanf("%d",&k);
            arr[j]=k;
        }
        if(arr[p-1]==0){
            printf("NO\n");
        } else if(arr[arr[p-1]]>0&&arr[arr[arr[p-1]]]>0){
            printf("YES\n");
        }
    }
    return 0;
}


#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; i++)
    {
        int x, abc[3];
        scanf("%d", &x);
        scanf("%d %d %d", &abc[0], &abc[1], &abc[2]);

        int key1 = abc[x] if (abc[key1] != 0)
        {
            print("YES");
        }
        else
        {
            print("NO");
        }
    }
}


#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; i++)
    {
        int x, abc[3];
        scanf("%d", &x);
        scanf("%d %d %d", &abc[0], &abc[1], &abc[2]);

        int key1 = abc[x];
        if (abc[key1] != 0)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
}


#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; i++)
    {
        int x, abc[3];
        scanf("%d", &x);
        scanf("%d %d %d", &abc[0], &abc[1], &abc[2]);

        int key1 = abc[x - 1];
        if (abc[key1 - 1] != 0)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
}


#include <stdio.h>

int main()
{
    int t,x,a,b,c;
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {
        scanf("%d",&x);
        scanf("%d %d %d",&a,&b,&c);
        switch (x)
        {
            case 1: switch (a)
                       {
                           case 0: printf("NO\n");
                         case 2:if(b==3)
                                  printf("YES\n");
                                  else
                                     printf("NO\n");
                                  break;

                         case 3:if(c==2)
                                 printf("YES\n");
                                 else
                                     printf("NO\n");
                                  break;

                                  printf("NO\n");
                        }
                      break;
              case 2: switch (b)
                       {
                           case 0: printf("NO\n");
                         case 1:if(a==3)
                                  printf("YES\n");
                                  else
                                     printf("NO\n");
                                  break;

                         case 3:if(c==1)
                                 printf("YES\n");
                                 else
                                     printf("NO\n");
                                  break;

                                  printf("NO\n");
                        }   break;

                  case 3: switch (c)
                       {
                           case 0: printf("NO\n");
                         case 2:if(b==1)
                                  printf("YES\n");
                                  else
                                     printf("NO\n");
                                  break;

                         case 1:if(a==2)
                                 printf("YES\n");
                                 else
                                     printf("NO\n");
                                  break;

                                  printf("NO\n");
                        }
                        break;
                        printf("NO\n");

        }

    }

    return 0;
}


#include <stdio.h>
int main(){

	//identiy the variables
	int a=0,b=0,c=0;
	int k; //the number you are holding
	int a_,b_,c_; //the keys behind

	//request the input from the user
	printf("What number is the key in your hand?\n");
	scanf("%d",&k);
	printf("Please write the key numbers behind doors you open respectively:");
	scanf("%d%d%d",&a_, &b_,&c_);

	//all possible false returns

	//you are holding number 1 on your hands

	if(k==1){
		if(a_==0){
			printf("Sorry, no way you can open all the doors.\n");
			return 0;
		}
		else if(a_==2 && b_==0){
			printf("Sorry, no way you can open all the doors.\n");
			return 0;
		}
		else if(a_==3 && c_==0){
			printf("Sorry, no way you can open all the doors.\n");
			return 0;
		}
		else{
			printf("Now you can open the doors\n.");
			return 1;
		}
	}

	//you are holding number 2 on your hands

		if(k==2){
			if(b_==0){
				printf("Sorry, no way you can open all the doors.\n");
				return 0;
			}
			else if(b_==1 && a_==0){
				printf("Sorry, no way you can open all the doors.\n");
				return 0;
			}
			else if(b_==3 && c_==0){
				printf("Sorry, no way you can open all the doors.\n");
			}
			else{
				printf("Now you can open the doors\n.");
				return 1;
			}
		}
	//you are holding number 3 on your hands

		if(k==3){
			if(c_==0){
				printf("Sorry, no way you can open all the doors.\n");
				return 0;
			}
			else if(c_==1 && a_==0){
				printf("Sorry, no way you can open all the doors.\n");
				return 0;
			}
			else if(c_==2 && b_==0){
				printf("Sorry, no way you can open all the doors.\n");
				return 0;
			}
			else{
				printf("Now you can open the doors\n.");
				return 1;
			}
		}
return 0;
}


#include <stdio.h>

int main(){

	//identiy the variables
	int a=0,b=0,c=0;
	int k; //the number you are holding
	int a_,b_,c_; //the keys behind

	//request the input from the user
	printf("What number is the key in your hand?\n");
	scanf("%d",&k);
	printf("Please write the key numbers after each door:");
	scanf("%d %d %d",&a_, &b_,&c_);

	if(k == 1){
		if(a_ == 0){
			printf("NO");
		}
		else if(a_ == 2 && b_ == 0){
			printf("NO");
		}
		else if(a_ == 3 && c_ == 0){
			printf("NO");
		}
		else{
			printf("YES");
		}

	else if(k == 2){
		if(b_ == 0){
			printf("NO");
		}
		else if(b_ == 1 && a_ == 0){
			printf("NO");
		}
		else if(b_ == 3 && c_ == 0){
			printf("NO");
		}
		else{
			printf("YES");

	else{
		if(c_ == 0){
			printf("NO");
		}
		else if(c_ == 1 && a_ == 0){
			printf("NO");
		}
		else if(c_ == 2 && b_ == 0){
			printf("NO");
		}
		else{
			printf("YES");

	}

	return 0;

	}


#include<stdio.h>
int main()
{
    int x,a,b,c,t,i,count=0;
    int arr[3];
    scanf("%d",&t);
    if(1<=t<=18)
    {
        while(t--)
       {

        scanf("%d",&x);
        for(i=0; i<3; i++)
        {
            scanf("%d",&arr[i]);
        }

            for(i=0; i<3; i++)
            {
                if(arr[x-1]!=0)
                {
                    x=arr[x-1];
                    count++;
                }
                if(arr[x-1]==0)
                    break;

            }

        if(count==2)
            printf("YES");
        else
            printf("NO");
    }}
}


#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int x,a[3],i,sum=0;
        scanf("%d",&x);
        for(i=0;i<3;i++){
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        int r=0;
        for(i=0;i<3;i++){
            if(a[x-1]==0 || a[sum]==0){
                r=1;
            }
        }
        if(r){
            printf("NO\n");
        }else
        {
            printf("YES\n");
        }

    }

    return 0;
}


#include<stdio.h>
int q,l,b[4];
int main() {
    scanf("%d",&q);
    while(q--) {
        scanf("%d%d%d%d",&l,b+1,b+2,b+3);
        if (b[b[l]]!=0) {
            printf("YES");
        }
        else {
            printf("NO");
        }
    }
    return 0;

}


#include<stdio.h>
int main(){
    int k;
    scanf("%d",&k);
    while(k--){
        int n;
        scanf("%d",&n);
        int arr[3];
        for(int i=0;i<3;i++){
            scanf("%d",&arr[i]);
        }
        int count=0;
        int tem=arr[n-1];
        while(tem!=0){
            tem=arr[temp-1];
            count=count+1;
        }
        if (count==2){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
}


#include<stdio.h>
int main(){
    int k;
    scanf("%d",&k);
    while(k--){
        int n;
        scanf("%d",&n);
        int arr[3];
        for(int i=0;i<3;i++){
            scanf("%d",&arr[i]);
        }
        int count=0;
        int tem=arr[n-1];
        while(tem!=0){
            tem=arr[n-1];
            count=count+1;
        }
        if (count==2){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int t;
    scanf("%d", &t);

    while(t--)
    {
        int m, x, a[4];
        scanf("%d", &m);
        scanf("%d %d %d", &a[1], &a[2], &a[3]);
        if(a[m]!=0)
        {
            x=a[m];
            if(a[x]!=0)
                printf("YES\n");
        }
        else
            printf("NO\n");
    }

    return 0;
}


#include <stdio.h>
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int x;
        scanf("%d", &x);
        int a, b, c, i;
        int s[3];
        scanf("%d %d %d", &a, &b, &c);
        for(i = 1; i <= 3; i++)
        {
            s[1] = a;
            s[2] = b;
            s[3] = c;
        }
        for(i = 1; i <= 3; i++)
        {
            //printf("%d\n", s[i]);
            if(s[x] == 0)
            {
                printf("NO\n");
                break;
            }
            else
            {
                if(s[x] == i)
                {
                    printf("%d\n", s[x]);
                    if(s[i] == 0)
                    {
                        printf("NO\n");
                        break;
                    }
                    else
                    {
                        printf("%d\n", s[i]);
                        if(s[i] == 0)
                        {
                            printf("NO\n");
                            break;
                        }
                        else
                        {
                            printf("YES\n");
                        }
                    }
                }
            }
        }
    }
    return 0;
}


#include <stdio.h>
int main()
{
    int t,i;
    scanf("%d",&t);
    for(i=0;i<t;i++){
        int x,a,b,c;
        scanf("%d",&x);
        scanf("%d %d %d",&a,&b,&c);
        if(x==1){
            x=a;
            if(x==2){
                x=b;
                if(x==3){
                    printf("YES\n");
                }
                else{
                    printf("NO\n");
                }
            }
            else if(x==3){
                x=c;
                if(x==2){
                    printf("YES\n");
                }
                else{
                    printf("NO\n");
                }

            }
            else{
                printf("NO\n");
            }
        }
        else if(x==2){
            x=b;
            if(x==1){
                x=a;
                if(x==3){
                    printf("YES\n");
                }
                else{
                    printf("NO\n");
                }
            }
            else if(x==3){
                x=c;
                if(x==1){
                    printf("YES\n");
                }
                else{
                    printf("NO\n");
                }

            }
            else{
                printf("NO\n");
            }
        }
        else if(x==3){
            x=c;
            if(x==2){
                x=b;
                if(x==1){
                    printf("YES\n");
                }
                else{
                    printf("NO\n");
                }
            }
            else if(x==1){
                x=a;
                if(x==2){
                    printf("YES\n");
                }
                else{
                    printf("NO\n");
                }
            }
            else{
                printf("N0\n");
            }
        }
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n, x,i,flag;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&x);
        int a[3];
        for(i=0; i<3; i++)
        {
            scanf("%d",&a[i]);
        }
        for(int j=1; j<=2; j++)
        {
            if(a[x-1]==0)
            {
                printf("NO\n");
                flag=1;
                break;
            }
            else
            {
                x=a[x-1];
                flag=0;
            }
        }
        if(flag==0)
           {

            printf("YES\n");}
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n, x,i,flag;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&x);
        int a[3];
        for(int j=0; j<3; j++)
        {
            scanf("%d",&a[i]);
        }
        for(int j=1; j<=2; j++)
        {
            if(a[x-1]==0)
            {
                printf("NO\n");
                flag=1;
                break;
            }
            else
            {
                x=a[x-1];
                flag=0;
            }
        }
        if(flag==0)
           {

            printf("YES\n");}
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int a,b,c,x;
        scanf("%d",&x);
        scanf("%d %d %d", &a, &b, &c);
        if(b==1)
        {
            printf("YES\n");
        }
        else printf("NO\n");
    }
}


#include<stdio.h>

int main()
{
	int n, m;
	int a, b, c;
	scanf("%d", &m);
	for (int i = 0; i < m; i++)
	{
		scanf("%d", &n);
		scanf("%d %d %d", &a, &b, &c);
		if (a == 1 || b == 2 || b == 3)
			printf("NO\n");
		else if (n == 1 && a == 0)
			printf("NO\n");
		else if (n == 2 && b == 0)
			printf("NO\n");
		else if (n == 3 && c == 0)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*
	  MADE BY carder
   __________________
  | ________________ |
  ||          ____  ||
  ||   /\    |      ||
  ||  /__\   |      ||
  || /    \  |____  ||
  ||________________||
  |__________________|
  \###################\
   \###################\
    \        ____       \
     \_______\___\_______\

 An AC a day keeps the doctor away.
*/
int t,x,carder[5];
bool f[5];
/*
       @carder周边
┏┳━━━━━━━━┓
┃┃████████┃
┃┃████┏━┓█┃
┃┃████┃打┃█┃
┣┫████┃暴┃█┃
┃┃████┃力┃█┃
┃┃████┃教┃█┃
┃┃████┃程┃█┃
┃┃████|c++┃█┃
┣┫████┗━┛█┃
┃┃████████┃
┃┃████████┃
┃┃███定价５00元┃
┗┻━━━━━━━━┛
    限时8折！！！
*/

/*
           仅供参考，抄袭（借鉴）可耻！
           【For reference only, shame on you for copying!】
           ___________________
		  |                  |
		  |    NO COPYING    |
		  |                  |
		  -------------------
*/
int main()
{
	cin>>t;
	while(t--)
	{
	   	cin>>x;
		cin>>carder[1];
		cin>>carder[2];
		cin>>carder[3];
	   	if(carder[x])
		{
			f[x]=1;
		}
	   	else
		{
	   		puts("NO");
	   		continue;
	   	}
	   	if(carder[carder[x]])
		{
		   	f[carder[x]]=1;
		}
	   	else
		{
	   		puts("NO");
	   		continue;
	   	}
	   	if(carder[carder[carder[x]]]==0)
	    {
	    	f[carder[carder[x]]]=1;
	    }
	   	if(f[1]==1&&f[2]==1&&f[3]==1)
		{
		   	puts("YES");
		}
	   	else
		{
		   	puts("NO");
		}
    }
}


#include<stdio.h>
int main()
{
   int t,x,a,b,c;
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {
        scanf("%d",&x);
        scanf("%d %d %d",&a,&b,&c);
        switch(x)
        {
            case 1:if(a==0)printf("NO");
                else if(a==2&&b!=0||a==3&&c!=0)
                    printf("YES");
                else printf("NO");
            case 2:if(b==0)printf("NO");
                else ifi(b==1&&a!=0||b==3&&c!=0)printf("YES");
                else printf("NO");
            case 3:if(c==0)printf("NO");
                else if(c==1&&a!=0||c==2&&b!=0)printf("YES");
                else printf("NO");
        }
    }
}


#include<stdio.h>
int main()
{
   int t,x,a,b,c;
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {
        scanf("%d",&x);
        scanf("%d %d %d",&a,&b,&c);
        switch(x)
        {
            case 1:if(a==0)printf("NO\n");
                else if(a==2&&b!=0||a==3&&c!=0)
                    printf("YES\n");
                else printf("NO\n");
            case 2:if(b==0)printf("NO\n");
                else if(b==1&&a!=0||b==3&&c!=0)printf("YES\n");
                else printf("NO\n");
            case 3:if(c==0)printf("NO\n");
                else if(c==1&&a!=0||c==2&&b!=0)printf("YES\n");
                else printf("NO\n");
        }
    }
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int t,n,i,j,T[3],k=3;
    scanf("%d",&t);
    for(i = 0 ; i < t ; i++){
        scanf("%d",&n);
        for(j = 0 ; j < 3 ; j++){
            scanf("%d",&T[j]);
        }
        n=n-1;
        k=3;
        while(k!=0){
            if(T[n]==0){
                printf("NO\n");
                break;
            }else{
                n=T[n];
                k--;
            }
        }
        if(k==0){
            printf("YES\n");
        }
    }
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int t,n,i,j,T[3],k;
    scanf("%d",&t);
    for(i = 0 ; i < t ; i++){
        scanf("%d",&n);
        for(j = 0 ; j < 3 ; j++){
            scanf("%d",&T[j]);
        }
        n=n-1;
        k=3;
        while(k!=0){
            if(T[n]==0){
                printf("NO\n");
                break;
            }else{
                n=T[n]-1;
                k--;
            }
        }
        if(k==0){
            printf("YES\n");
        }
    }
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
    int val;
    int cost;
} data;

int cmp(const void *a, const void *b) {
    return (*(data *) a).val - (*(data *) b).val;
}

int main(int argc, const char* argv[]) {
    int t;
    scanf("%d", &t);
    while (t--) {
        int x;
        int a, b, c;
        scanf("%d%d%d%d", &x, &a, &b, &c);

        int taken[3] = {0, 0, 0};
        int ok = 1;
        for (int i = 0; i < 3; i++) {
            switch (x) {
                case 1:
                    x = a;
                    taken[0] = 1;
                    break;
                case 2:
                    x = b;
                    taken[1] = 1;
                    break;
                case 3:
                    x = c;
                    taken[2] = 1;
                    break;
                case 0:
                    break;
            }
        }

        for (int i = 0; i < 2; i++) {
            if (taken[i] == 0) {
                ok = 0;
                break;
            }

        }
        if (ok == 1) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }

    }

    return 0;
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="three doors.3" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/three doors.3" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/three doors.3" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
		</Compiler>
		<Unit filename="main.c">
			<Option compilerVar="CC" />
		</Unit>
		<Extensions>
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#define f_sc(a) scanf("%f",&a)
#define i_sc(a) scanf("%d",&a)
#define ll_sc(a) scanf("%lld",&a)
#define c_sc(a) scanf(" %c",&a)
#define s_sc(a) scanf("%s",a)
#define f_pr(a) printf("%.15f",a)
#define i_pr(a) printf("%d ",a)
#define ll_pr(a) printf("%lld ",a)
#define s_pr(a) printf("%s ",a)
#define c_pr(a) printf("%c",a)
#define MaxCompare(a, b) (((a) > (b)) ? (a) : (b))
#define MinCompare(a, b) (((a) > (b)) ? (b) : (a))
#define abs(a) (((a) > 0) ? (a) : (-(a)))
#define MAX 281202
#define K 500
int main()
{
    int t;
    scanf("%d\n",&t);
    while(t--)
    {
        //n is the key on your hand
        int n;
        scanf("%d",&n);
        int a[n];
        int s=0;
        int count=1;
        for(int i=0; i<3; i++)
        {
            i_sc(a[i]);
        }
        for(int i=0; i<2; i++)
        {
            for(int j=1; j<3; j++)
            {
                if(a[i]>a[j])
                {
                    int c=a[i];
                    a[i]=a[j];
                    a[j]=c;
                }
            }
        }
        for(int i=0; i<3; i++)
        {
            //i_pr(a[i]);
            if(n>=a[i]) n=n+a[i];
            else count=0;
        }
        if(count==0) printf("NO");
        else printf("YES");
        printf("\n");
    }
}


#include <stdio.h>

int main() {
    int t;
    scanf("%d",&t);
    while(t>0){
        int n;
        scanf("%d",&n);
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        int arr[3]={a,b,c};
        int e=arr[n-1];

        if(e==0)
        printf("NO\n");
        else{
            if(arr[e-1]==0){
                printf("NO");
            }
            else{
            printf("YES\n");}
            }
        t--;
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int open(int x, int * doors) {
    if (doors[x-1] == 0) return 0;
    if (doors[doors[x-1]-1] == 0) return 0;
    return 1;
}

int main() {
    int t;
    scanf("%d", &t);
    for (int i=0;i<t; i++) {
        int x;

        int doors[3];

        scanf("%d", &x);
        scanf("%d %d %d", doors, doors+1, doors+2);

        if (open(x, doors) == 1) printf("YES");
        else printf("NO");
    }
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
    int t,a,b,c,flag,x;
    scanf("%d",&t);
    if(t<=18)
    {
        for(int i=0;i<t;i++)
        {
            scanf("%d",&x);

             scanf("%d%d%d",&a,&b,&c);

        if(x<=3 && a<=3 && b<=3 && c<=3)
        {
            flag=0;
            while(flag!=3)
            {
                if(x==0)
                {
                    break;
                }
                       if(x==3 && c==3)
                       {
                           break;
                       }
                       if(x==1)
                       {
                           x=a;
                           flag++;
                       }
                       else if(x==2)
                       {
                           x=b;
                           flag++;
                       }
                       else if(x==3)
                       {
                           x=c;
                           flag++;
                       }
            }
        }
            if(flag==3)
            {
                printf("YES");

            }
            else
                printf("NO");

        }
        }

}


#include<stdio.h>

    int main(){
    int t;
    scanf("%d",&t);

    for (int i = 0; i < t; i++)
    {
        int x,a,b,c;
        scanf("%d",&x);
        scanf("%d %d %d",&a,&b,&c);
        int count = 6;

        for (int j = 0; j < 3; j++)
        {
            if (x==3)
        {
            count-=x;
            x = c;
        }

        else if (x==2)
        {
            count-=x;
            x=b;
        }

        else if (x==1)
        {
            count-=x;
            x=a;
        }

        else
        {
            printf("NO\n");
            break;
        }

        }

        if(count==0){
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }

    }

    return 0;
}


#include<stdio.h>
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
    int i,n,a[4],flag=0;
    scanf("%d",&n);
    for(i=1;i<=3;i++){
        scanf("%d",&a[i]);
    }
    for(i=1;i<=3;i++){
        if(a[n]!=0 && a[a[n]]!=0)
            flag++;

    }
    if(flag==0)
        printf("N0\n");
    else
        printf("YES\n");
}
}


#include<stdio.h>
int main(){
int t,i,j,key,flag=0;
int key_behind_door[4];
scanf("%d",&t);
for(i=0; i<t; i++){
   scanf("%d",&key);
    for(j=1; j<=3; j++){
        scanf("%d",&key_behind_door[j]);
    }
    for(j=1; j<=2; j++){
      if(key_behind_door[key]!=0){
            key=key_behind_door[key];
            flag=1;

      }
      else
        flag=0;
    }
    if(flag==1){
        printf("YES");
    }
    else
        printf("NO");

}

return 0;
}


#include <stdio.h>
int main()
{
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; i++)
    {
        int x, arr[3], y = 0;
        scanf("%d", &x);
        for (int j = 0; j < 3; j++)
        {
            scanf("%d", &arr[j]);
        }
        for (int j = 0; j < 2; j++)
        {
            if (arr[x - 1] == 0)
            {
                printf("NO");
                y = 1;
                break;
            }
            else
            {
                x = arr[x - 1];
            }
        }
        if (y == 0)
            printf("YES");
    }
    return 0;
}


#include <stdio.h>
int main()
{

    int b;
    scanf("%d", &b);
    while (b--)
    {
        int a;
        int b, c, d;
        scanf("%d", &a);
        int dorrkey[4];
        for (int i = 0; i < 3; i++)
        {

            scanf("%d", &dorrkey[i]);
        }
        int ans = 0;
        for (int i = 0; i < 3; i++)
        {
            if (dorrkey[a - 1] != 0)
            {
                ans++;

                a = dorrkey[a - 1];
            }
        }
        if (ans == 2)
        {
            printf("YES");
        }
        else
        {
            printf("NO");
        }
    }
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int check(int n)
{
  int k,count=0,i,even=0,odd=0,n1,n2,n3;
k=n;
int arr[3];
for(int i=0;i<3;i++){
       scanf("%d",&arr[i]);}

n1=arr[k-1];
n2=arr[n1-1];
n3=arr[n2-1];

   if(n1!=n2&&n2!=n3&&n3!=n1)
    return 1;

  else

  return 0;

}

int main() {
int t,n,c=0;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
scanf("%d",&n);
   c=check(n);
   if(c==0)
    printf("NO\n");
    else
        printf("YES\n");
}

    }


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
int cmp(const void* a,const void* b)
{
    return (*(int*)a-*(int*)b);
}
void input(int ar[],int n)
{
    for(int i=0;i<n;i++)
        scanf("%d",&ar[i]);
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int k=0;k<t;k++)
    {
        int n;
        scanf("%d",&n);
        int ar[3];
        input(ar,3);
        if(n==3)
        {
            if((ar[2]==1 && ar[0]==2)||(ar[2]==2 && ar[1]==1))
                printf("YES\n");
            else
                printf("NO\n");
        }
        if(n==2)
        {
            if((ar[1]==1 && ar[0]==3)||(ar[1]==3 && ar[2]==1))
                printf("YES\n");
            else
                printf("NO\n");
        }
        if(n==1)
        {
            if((ar[0]==2 && ar[1]==3)||(ar[0]==3 && ar[2]==1))
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
}


#include<stdio.h>

int main()
{
    int t,x,i,a[4];
    scanf("%d",&t);
    while(t--)
    {
        int cnt=0;
        scanf("%d",&x);
        for(i=1; i<=3; i++)
        {
            scanf("%d",&a[i]);
        }
        for(i=1; i<=3; i++)
        {
            if(a[x]!=0)
            {
                x=a[x];
            }
            else if(a[x]==0 && i!=3)
            {
                cnt=1;
                break;
            }
        }
        cnt==0?printf("YES\n"):printf("NO\n");

    return 0;
}


#include<stdio.h>

int main()
{
    int n,x,a,b,c;
    scanf("%d",&n);

    while(n--)
    {
        scanf("%d",&x);
        scanf("%d%d%d",&a,&b,&c);
        if(x==1)
        {
            if(a==1 || a==2)
                printf("YES\n");
            else
                printf("NO\n");

        }

    else if(x==2)
        {
            if(b==1 || b==2)
                printf("YES\n");
            else
                printf("NO\n");

        }

          else
        {
            if(c==1 || c==2)
                printf("YES\n");
            else
                printf("NO\n");

        }

    }

    return 0;

}


#include <stdio.h>
void main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int x,a[3],i,temp,count=0;
        scanf("%d",&x);
        for(i=0;i<3;i++)
        {
            scanf("%d",&a[i]);
        }
        temp=a[x-1];
        for(i=0;i<3;i++)
        {
            if(temp==0)
            {
                break;
            }
            else
            {
                temp=a[temp-1];
                count++;
            }

        }
        if(count==2)
        {
            printf("YES");

        }
        else{
            printf("NO\n");
        }

    }
}


#include<stdio.h>

int man(){
	int x  ;
	int ctr = 0 ;
	int n;
	scanf("%d" , &n);
	int arr[4];
	arr[0] = -1;
	for(int i = 1 ; i< 4 ; i++){
		scanf("%d" , &x);
		arr[i] = x ;
	}

	int num = n ;
	while(1){
		if(arr[num] !=0){
			ctr++ ;
		}
		else{
			break ;
		}
		num = arr[num] ;
	}
	// printf("%d\n" , ctr);
	if(ctr ==2){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}

}

int main(){
	int t ;
	scanf("%d" , &t);
	for(int i = 0 ; i<t ; i++){
	man()
}
}


#include <stdio.h>
int main(void) {
  int test;
  scanf("%d", &test);
  for (int t = 0; t < 4; t++) {
    int key, door1,door2,door3;
    scanf("%d", &key);
    scanf("%d %d %d", &door1, &door2, &door3);
    int unlock = 0;
    int yes = 1;
    while (unlock != 3) {
      if (key == 3) {
        unlock += 1;
        key = door3;
        if (key == 0 && unlock != 3) {
          yes = 0;
          break;
        }
      }
      if (key == 2) {
        unlock += 1;
        key = door2;
        if (key == 0 && unlock != 3) {
          yes = 0;
          break;
        }
      }
      if (key == 1) {
        unlock += 1;
        key = door1;
        if (key == 0 && unlock != 3) {
          yes = 0;
          break;
        }
      }
    }
    if (yes) {
      printf("YES\n");
    }
    else {
      printf("NO\n");
    }
  }
}


#include <stdio.h>
int main(){
    int t,x,a,b,c;
    scanf("%d",&t);
    for (int i=0;i<t;i++){
        scanf("%d",&x);
        scanf("%d %d %d",&a,&b,&c);
        int arr[3];
        arr[0]=a;
        arr[1]=b;
        arr[2]=c;
        if (a==1||b==2||c==3){
            printf("NO");
        }
        if (arr[x-1]==0){
            printf("NO");
        }
        else{
            printf("YES");
        }

}
}


#include<stdio.h>
#include <stdlib.h>
int main()
{
int i , j , J , a , b , c , m, p;
int T[3];
scanf("%d",&m);
for(i=1;i<=m;i++){
    scanf("%d",&p);
    for(J=0;J<3;J++)
        scanf("%d",&T[i]);
    if(T[p-1]==0)
        printf("NO\n");
    else{
        a = T[p-1];
        if(T[a-1]==0)
            printf("NO\n");
        else
            printf("YES\n");
    }
}
return 0;

}


#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; i++)
    {
        int x;
        int arr[3];

        scanf("%d", &x);
        for (int i = 0; i < 3; i++)
        {
            scanf("%d", &arr[i]);
        }
        if (arr[x - 1] == 0 || arr[arr[x - 1] - 1] == 0)
        {
            printf("NO");
        }
        else
        {
            printf("YES");
        }
    }
}


#include<stdio.h>

void can_door_be_opened(int x, int door[3]){
    int t=door[x-1];
    if(t==0){printf("NO");}
    else if(door[t-1]==0){printf("NO");}
    else printf("YES");
}

int main(){
    int T;
    scanf("%d",&T);
    for(int t=0;t<T;t++){
        int x;
        scanf("%d",&x);
        int door[3];
        for(int i=0;i<3;i++){scanf("%d",&door[i]);}
        can_door_be_opened(x,door);
    }
    return 0;
}


#include<stdio.h>
int main(){
    int t;
    scanf("%d",&t);
    int n,a[3];
    for(int i=0;i<t;i++){
        scanf("%d",&n);
        for(int j=0;j<3;j++){
            scanf("%d",&a[i]);
        }
        if(a[n]==0){
            printf("NO");
        }
        else if(a[a[n]]==0){
            printf("NO");
        }
        else{
            printf("YES");
        }
    }
}


#include <stdio.h>

int main()
{

    int n, a[3];
    int t;
    scanf("%d", &t);
    for(int i=0; i<t; i++)
    {
    scanf("%d", &n);
    scanf("%d %d %d", &a[0], &a[1], &a[2]);
    if(a[n-1]==0)
    printf("NO\n");
    else if(a[a[n-1]]==0)
    printf("NO\n");
    else
    printf("YES\n");
    }

}


#include<stdio.h>

void sol(){

    int x, a, b, c;
    scanf("%d", &x);
    scanf("%d %d %d", &a, &b, &c);

    if(a==1 || b==2 || c==3)
        printf("NO\n");
    else if( (x==1&&a==0) || (x==2&&b==0) || (x==3&&c==0) )
        printf("NO\n");
    else
        printf("YES\n");
    return;
}

int main(){

    int test;
    cin>>test;
    while(test--){
        sol();
    }
    return 0;
}


#include<stdio.h>
int main (){
    int t,x,a,b,c,flag;
    scanf("%d",&t);
    for(int i=0;i<t;i++){
        scanf("%d",&x);
        scanf("%d %d %d",&a,&b,&c);
        flag=0;
        if(x==1){
            if(a==0){
                printf("NO\n");
                break;
            }else if(a==2){
                if(b==0){
                    printf("NO\n");
                    break;
                }
            }else if(a==3){
                if(c==0){
                    printf("NO\n");
                    break;
                }
            }
            printf("YES\n");
        }
        else if(x==2){
            if(b==0){
                printf("NO\n");
                break;
            }else if(b==1){
                if(a==0){
                    printf("NO\n");
                    break;
                }
            }else if(b==3){
                if(c==0){
                    printf("NO\n");
                    break;
                }
            }
            printf("YES\n");
        }
        else if(x==3){
            if(c==0){
                printf("NO\n");
            }else if(c==1){
                if(a==0){
                    printf("NO\n");
                    break;
                }
            }else if(c==2){
                if(b==0){
                    printf("NO\n");
                    break;
                }
            }
            printf("YES\n");
        }

    }
    return 0;
}


#include <string.h>
#include <stdio.h>

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int key;
        int* arr = (int*)malloc(3*sizeof(int));
        scanf("%d", &key);
        scanf("%d%d%d", &arr[0], &arr[1], &arr[2]);
        for(int i=0; i < 3; i++){
            if(arr[key] == 0){
                break;
            } else {
                key = arr[key];
                arr[key] = 0;
            }
        }
        if(arr[0] == 0 && arr[1] == 0 && arr[2] == 0){
            printf("YES\n");
        } else { printf("NO\n"); }
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int tc,i;
    scanf("%d",&tc);
    while(tc--)
    {
        int x,a[3];
        scanf("%d",&x);
        scanf("%d %d %d",&a[0],&a[1],a[2]);
        if(a[x]!=0 && a[a[x]]!=0)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int key,arr[3];
        scanf("%d",&key);
        for(int i=0;i<3;i++){
            scanf("%d",&arr[i]);}
        if(arr[key-1]!=0){
            if(arr[arr[key-1]-1]!=0){
                printf("YES");
                continue;
            }
        }printf("NO");
    }
}


#include<stdio.h>
int main()
{
    int t,n,c;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        int a[4],i;
        for(i=1;i<=3;i++)
        {
            scanf("%d",&a[i]);
        }
         int c=0;
        while(1)
         {

             if(a[n]!=0)
             {
                 c++;
                 n=a[n];
             }
             else
             {
                 break;
             }
         }
         printf("%d\n",c);
         if(c==2)
         {
             printf("YES\n");
         }
         else
         {
             printf("NO\n");
         }

    }
    return 0;

}


#include<stdio.h>

int main()
{
    int t, x, a, b, c, flag = 0;
    scanf("%d", &t);

    for(int i = 0; i < t; i++){
        scanf("%d %d %d %d", &x, &a, &b, &c);
        for(int j = 0; j < 1; j++){
            if(x == 1){
                x = a;
            }
            if(x == 2){
                x = b;
            }
            if(x == 3){
                x = c;
            }
            if(x == 0){
                printf("NO\n");
                break;
            }
            else{
                printf("YES\n");
            }
        }
    }

    return 0;
}


#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        int currentKey;
        scanf("%d", &currentKey);
        int a1 = currentKey;
        int behindKey[3];
        for(int i = 0; i < 3; i++) {
            scanf("%d", &behindKey[i]);
        }
        int nextKey = behindKey[currentKey - 1];
        if (nextKey == 0) {
            printf("NO");
            continue;
        }
        int a2 = nextKey;
        nextKey = behindKey[nextKey - 1];
        if (nextKey == 0) {
            printf("NO");
            continue;
        }
        int a3 = nextKey;
        if (a1 != a2 && a1 != a3 && a2 != a3) {
            printf("YES");
        } else {
            printf("NO");
        }

    }

    return 0;
}


#include<stdio.h>
int main()
         { int t,i;
         scanf("%d",&t);
             for(i=1;i<=t;i++)
             {

             int x,a,b,c;
         scanf("%d",&x);
             scanf("%d%d%d",&a,&b,&c);

                if(x==1)
                {
                    if(a==0)
                        printf("NO\n");
                    else if(a==2&&b==0)
                    printf("NO\n");

                    else if(a==3&&c==0)
                        printf("NO\n");
                        else
                     printf("YES\n");

                }
                 if(x==2)
                {
                    if(b==0)
                        printf("NO\n");
                    else if(b==1&&a==0)
                    printf("NO\n");

                    else if(b==3&&c==0)
                        printf("NO\n");
                        else
                     printf("YES\n");

                }
                 if(x==3)
                {
                    if(c==0)
                        printf("NO");
                    else if(c==2&&b==0)
                    printf("NO\n");

                    else if(c==1&&a==0)
                        printf("NO\n");
                        else
                     printf("YES\n");

                }

           }

    return 0;
    }


#include<stdio.h>
int main()
         { int t,i;
         scanf("%d",&t);
             for(i=1;i<=t;i++)
             {

             int x,a,b,c;
         scanf("%d",&x);
             scanf("%d%d%d",&a,&b,&c);

                if(x==1)
                {
                    if(a==0)
                        printf("NO");
                    else if(a==2&&b==0)
                    printf("NO");

                    else if(a==3&&c==0)
                        printf("NO");
                        else
                     printf("YES");

                }
                 if(x==2)
                {
                    if(b==0)
                        printf("NO");
                    else if(b==1&&a==0)
                    printf("NO");

                    else if(b==3&&c==0)
                        printf("NO");
                        else
                     printf("YES");

                }
                 if(x==3)
                {
                    if(c==0)
                        printf("NO");
                    else if(c==2&&b==0)
                    printf("NO");

                    else if(c==1&&a==0)
                        printf("NO");
                        else
                     printf("YES");

                }

           }

    return 0;
    }


#include<stdio.h>

int main()
{
    int t, x, a, b, c;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d%d%d%d", &x, &a, &b, &c);
        int arr[3];
        arr[0]=a;
        arr[1]=b;
        arr[2]=c;
        if (arr[x-1]!=0 && arr[arr[x-1]]!=0)
            printf("YES\n");
//        else if (x==2 && b!=0)
//            printf("YES\n");
//        else if (x==3 && c!=0)
//            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


#include <stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int key, doors[3], i;
        scanf("%d", &key);
        scanf("%d %d %d", &doors[0], &doors[1], &doors[2]);
        for (i = 0; i < 3; i++)
        {
            int index = key;
            if (doors[index - 1] == 0)
            {
                if (i == 2)
                    printf("YES");
                else
                    printf("NO");
                break;
            }
            else if (doors[index - 1] == 1)
                key = 1;
            else if (doors[index - 1] == 2)
                key = 2;
            else
                key = 3;
        }
    }
}


#include <stdio.h>
int main()
{
    int t,x;
    int a[3];
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {
        scanf("%d",&x);
        for(int j=0;j<3;j++)
        {
            scanf("%d ",&a[j]);
        }

        if(a[x-1] !=0)
        {
            int m = a[x-1];
            if(a[m-1] !=0)
            {
                printf("YES");

            }
            else
            {
                printf("NO");
            }
        }
        else
        {
            printf("NO");
        }
    }

    return 0;
}


#include<stdio.h>
int num[19];
int main(){
	int a,b,count,current;
	scanf("%d",&a);
	while(scanf("%d",&b)!=EOF){
		count=0;
		for(int i=1;i<a;i++){
			scanf("%d",&num[i]);
		}
		current=b;
		while(num[current]){
			count++;
			current=num[current];
		}
		if(count==a-2)	printf("YES\n");
		else	printf("NO\n");
	}
	return 0;
}


#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);

    while(t--)
    {
        int k1, k2, k3;
        scanf("%d", &k1);

        int room[3];

        for(int i=0; i<3; i++)
        {
            scanf("%d", &room[i]);
        }

        int count = 0;

        if(room[k1-1] != 0)
        {
            count = count + 1;
            k2 = room[k1 - 1];
        }

        if(room[k2-1] != 0)
        {
            count = count + 1;
            k3 = room[k2 - 1];
        }

        if(count = 2)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }

    return 0;
}


/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

int main()
{
 int t,x,a,b,c;
 scanf("%d",&t);
 for(int i=0;i<t;i++){
     scanf("%d %d %d %d",&x,&a,&b,&c);
     if(x==1){
         if(a==0) printf("NO\n");
         else if(a==2){
             if(b==3) printf("YES\n");
             else printf("NO\n");
         }
         else if(a==3){
                          if(c==3) printf("YES\n");
             else printf("NO\n");
         }
     }
     else if(x==2){
          if(b==0) printf("NO\n");
         else if(b==1){
             if(a==3) printf("YES\n");
             else printf("NO\n");
         }
         else if(b==3){
                          if(c==1) printf("YES\n");
             else printf("NO\n");
         }
     }
     else{
          if(c==0) printf("NO\n");
         else if(c==2){
             if(b==1) printf("YES\n");
             else printf("NO\n");
         }
         else if(c==1){
                          if(a==2) printf("YES\n");
             else printf("NO\n");
         }
     }
 }

    return 0;
}


// Online C compiler to run C program online
#include <stdio.h>

int main() {
    // Write C code here
    //printf("Hello world");
    int t;
    scanf("%d",&t);
    int a[t],b[t][3];
    int o[t],x,y,z;
    for(int i=0;i<t;i++)
    o[i]=0;
    for(int i=0;i<t;i++)
    {
        scanf("%d",&a[i]);
        x=0;
        y=0;
        z=0;
        if(a[i]==1)
        ++x;
        else if(a[i]==2)
        ++y;
        else if(1)
        ++z;
        for(int j=0;j<3;j++)
        {
            scanf("%d",&b[i][j]);
            if(b[i][j]==1)
            ++x;
            else if(b[i][j]==2)
            ++y;
            else if(1)
            ++z;
        }
        if(x&&y&&z)
        o[i]=1;
    }
    for(int i=0;i<t;i++)
    {
        if(o[i])
        printf("YES\n");
        else
        printf("NO\n");
    }
    return 0;
}


#include <stdio.h>

int square(int n)
{
    int i=1;
    int sum=0;
    while(i*i<n)
    {
       sum=sum+1;
      i++;
    }
    return sum;
}
int cube(int n)
{
    int i=1;
    int sum=0;
    while(i*i*i<n)
    {
        sum=sum+1;
        i++;
    }
    return sum;
}
int sqrcube(int n)
{
    int i=1;
    int sum=0;
    while(i*i*i<n)
    {
        for(long int j=1;j<=i*i;j++)
        {
            if(j*j == i*i*i)
            {
                 sum = sum + 1;
            }
        }
        i++;
    }
    return sum;
}
int main()
{
    int n;
    int i;
    scanf("%d", &n);
    int N[n];
    for(i=0;i<n;i++)
    {
        scanf("%d", &N[i]);
    }
    for(i=0;i<n;i++)
    {
    printf("%d", square(N[i])+cube(N[i])-sqrcube(N[i]));
    }
}


#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#define UF64 SCNu64
#define UF32 SCNu32
#define UF16 SCNu16
#define UF8  SCNu8
uint64_t number(uint64_t);
int main(){
  uint8_t no_cases;
  scanf("%"UF8,&no_cases);
  uint64_t cases[no_cases];
  for(uint8_t i=0; i<no_cases; i++){
    scanf("%"UF64, &cases[i]);
  }
  for(uint8_t i=0; i<no_cases; i++){
    printf("%"UF64"\n", number(cases[i]));
  }
  return 0;
}
uint64_t number(uint64_t input){
  if(input==1 && input==2) return 1;
  uint64_t sl,cl,red=0;
  for(uint64_t i=2; i<input; i++){
    if(i*i == input) {sl=i; break;}
    if(i*i > input) {sl=i-1; break;}
  }
  for(uint64_t i=2; i<input; i++){
    if(i*i*i == input) {cl=i; break;}
    if(i*i*i > input) {cl=i-1; break;}
  }
  for(uint64_t i=1; i<=cl; i++){
    for(uint64_t j=1; j<=sl; j++){
      if(i*i*i == j*j) red++;
    }
  }
  return sl+cl-red;
}


#include<stdio.h>
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		long long n;
		scanf("%lld",&n);
		int x=0;
		int i;
		for(i=2;i*i<=n;i++){
			if(i*i<=n){
				x++;
			}
		}
		int y=0;
		for(i=2;i*i*i<=n;i++){
			if(i*i*i<=n){
				y++;
			}
		}
		printf("%d\n",x+y+1);
	}
	return 0;
}


#include <stdio.h>

int main() {
    int t, n, i = 1;

    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);
        while(i * i <= n && n != 1) {
            if(i * i <= n) i++;
            if(i * i * i  <= n) i++;
        }
        printf("%d", i);
    }

    return 0;
}


#include<stdio.h>
int main(){
    int i, n;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        int m;
        scanf("%d",&m);
        int p, q,s=0;
        for(p=1;p*p*p<=m;p++){
            for(q=1;q*q<=m;q++){
                if(p*p*p==q*q){
                    s++;
                }
            }
        }

        p=p-1;
        q=q-1;
        printf("%d", p+q-s);
    }
    return 0;
}


#include <stdio.h>
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		long long int cnt=1,cnt2=0,i=2,j=2,n,a,b;
		scanf("%lld",&n);
		a=i*i;
		b=i*a;
		for(i=2;(a<=n)||(b<=n);i++)
		{
			a=i*i;
			b=i*a;
			if(a<=n) cnt++;
			if(b<=n) cnt++;
		}
		a=j*j;
		b=a*j;
		for(i=2;a<=n;i++)
		{
			a=i*i;
			for(j=2;b<=a;j++)
			{
				b=j*j*j;
				if(a==b)
				{
					cnt2++;
					break;
				}
			}
		}
		printf("%lld\n",cnt-cnt2);
	}
	return 0;
}


#include <stdio.h>  //getchar putchar (f)scanf (f)printf
#include <string.h> // strlen
#include <stdlib.h> // qsort bsearch abs calloc
#include <ctype.h> // isalpha isdigit isupper islower isspace
#include <limits.h> // INT_MAX INT_MIN UINT_MAX
#include <math.h>

typedef long long int LL;
typedef unsigned long long int ULL;
const int M = 100005;
const int M15 = 100005;
const int M25 = 200005;
const int M35 = 300005;
const int M45 = 400005;
const int M55 = 500005;

const int N = 102;
const int A = 26;
const int mod = 998244353;

LL gcd(LL a, LL b){return b ? gcd(b,a%b) : a;}
LL maxl(LL a, LL b){if(a>b) return a; else return b;}
LL minl(LL a, LL b){if(a<b) return a; else return b;}
int max(const int a, const int b){ if(a>b) return a; else return b;}
int min(const int a, const int b){ if(a<b) return a; else return b;}
int cm(const void *a, const void *b){return *(int *)a - *(int *)b;}
int cmr(const void *a, const void *b){return *(int *)b - *(int *)a;}
int cmll(const void *a, const void *b){ if(*(LL *)a>*(LL *)b) return 1; else if(*(LL *)a<*(LL *)b) return - 1; else return 0;}
int cmrll(const void *a, const void *b){if(*(LL *)a<*(LL *)b) return 1; else if(*(LL *)a>*(LL *)b) return - 1; else return 0;}
int cmc(const void *a, const void *b){ return *(char *)a - *(char *)b;}
LL rd(){
    LL a = 0, d = 10ll;
    int flag = 1;
    char c = getchar();
    while( isspace(c) ) //c == ' ' || c == '\n' || c == '\t' )
        c = getchar();
    if(c == '-'){
        flag = -1;
        c = getchar();
    }
    while(isdigit(c)){
        a = a * d + c - '0';
        c = getchar();
    }
    return a * flag;
}
void wd(LL a){
    if(a<0){
        putchar('-');
        a *= -1;
    }

    char b[128], i = 0;

    while(a){
        b[i] = a % 10;
        a /= 10;
        i++;
    }
    if(i--)
        while(i>=0){
            putchar('0'+b[i]);
            i--;
        }

    else
        putchar('0');

    putchar(' ');
    return;
}
/*
int simple(int *si, int *dig){
    int i,j,k = 0;
    for(i=2; i < M ; i++ ){
        if(dig[i] == 0){
            dig[i] = i;
            si[k] = i; k++;
        }
        for(j = 0; j < k && i * si[j] < M && si[j] <= dig[i] ; j++)
            dig[ i * si[j] ] = si[j];
    }
    return k;
}  // решето Эратосфена с линейным временем работы
LL getp(int l, int r, int *a){
    if(r - l == 1){
        return (LL)a[l] * (LL)a[r];
    }
    else if ( r > l + 1){
        int i ,m, mn = INT_MAX;
        for(i=l; i<=r; i++){
            if(a[i] < mn){
                mn = a[i];
                m = i;
            }
        }
        LL t = maxl( (LL)a[m] * (LL)a[m-1] , (LL)a[m] * (LL)a[m+1] );
        return  maxl( t, maxl(getp(l,m-1,a), getp(m+1,r,a)) );
    }
    else{
        return 1ll;
    }
}
int sumd(LL n){
    int s = 0;
    if(n < 0)
        n *= -1;
    while(n){
        s += n % 10;
        n /= 10;
    }
    return s;
}
int min11(LL x){
    int i;
    return 00000000;
}
int getk(LL x){
    int i,c = 0;
    int a[10] = {0,0,0,0,0,0,0,0,0,0};
    while(x){
        a[x % 10]++;
        x /=10;
    }
    for(i=0;i<10;i++){
        if(a[i] > 0){
            c++;
        }
    }
    return c;
}
int getkeq(LL x){
    int i = 0,c = 0;
    int a[10] = {0,0,0,0,0,0,0,0,0,0};
    while(x){
        a[i] = x % 10;
        x /=10;
        i++;
    }

    for(;i>0;i--){
        if(a[i] == a[i-1]){
            c++;
        }
    }
    return c;
}
int d2(LL a, LL b){
    char sa[32], sb[32];
    int i,j,la = 0, lb = 0,c = 0;
    while(a){
        sa[la] = a % 10 + '0';
        a /= 10;
        la++;
    }
    sa[la] = '\0';

    while (b){
        sb[lb] = b % 10 + '0';
        b /= 10;
        lb++;
    }
    sb[lb] = '\0';

    strrev(sa);
    strrev(sb);

    for(i=0, j = 0 ; i<la && j < lb ; j++)
        if(sa[i] == sb[j]){
            i++;
            c++;
        }
    return lb+la-2*c;
}   // вычисление макс.длинны подпоследовательности цифр двух чисел
*/
/*
int fm(int *a, int l, int r, int k){
    int i, t = a[0];
    int m = ( r - l + 1) / 2;
    for(i=0;i<n;i++){
        ;
    }

    return
} // поиск в массиве a с позиции l по r  k-ой медианы ( l <= k <= r)
*/
int main(){
    int i,j,k,a[33000],b[1002],c[35000];
    a[0] = 0;
    for(i=1; i <= 31623; i++){
        a[i] = i * i;
    }
    a[i] = 1000000000 + 5;

    b[0] = 0;
    for(i=1; i  <= 1000; i++){
        b[i] = i * i * i;
    }
    b[i] = 1000000000 + 5;

    //mergre
    c[0] = 0;
    for(i = 1, j = 1, k = 1 ; i + j <= 32623 ; k++){
        if(a[i] < b[j]){
            c[k] = a[i];
            i++;
        }
        else if(a[i] > b[j]){
            c[k] = b[j];
            j++;
        }
        else{
            c[k] = a[i];
            i++;
            j++;
        }
    }

   // printf("c\n");

    int t = 1;
    scanf("%i", &t);
    //printf("%i\n",t);
    while(t--){

        int n,m = 1;
        scanf("%i",&n);

        int l = 1;
        int r = k;

        while(l<=r){
            m = (r + l) / 2;
            if (c[m] > n)
                    r = m - 1;
            else if (c[m] < n)
                    l = m  + 1;
            else
                break;
        }

        if(c[m - 1] > n)
            m--;

        printf("%i\n",m);
    }

    /*
    int i, n, m;
    long long int a[M25], sum = 0ll, mx = -1;
    scanf("%i",&n);
    for(i=0;i<n;i++){
        a[i] = rd();
        sum += a[i];
        mx = maxl(mx,a[i]);
    }
    sum -= mx;
    scanf("%i",&m);
    for(i=0;i<m;i++){
        long long int x,y,ans = 0;
        x = rd();
        y = rd();
        ans += maxl(0,x - mx)
        printf("%lli\n",ans);
    }
    */

    int ans = 0 + 0 * 0;
    return ans;
}


// LUOGU_RID: 94347011
#include <stdio.h>
#include <math.h>

int main()
{
	int t, n, num[20], sum, a;
	scanf("%d", &t);
	for (int i = 0; i < t; i++)
	{
		num[i] = -1;
		int j = 0;
		scanf("%d", &n);
		do
		{
			j++;
			num[i]++;
			sum = j * j;
		} while (sum <= n);
		j = 0;
		sum = 1;
		a = 0;
		do
		{
			j++;
			for (int k = 1; k * k <= j; k++)
			{
				if (k * k == j)
				{
					a = 0;
					break;
				}
				a = 1;
			}
			num[i] += a;
			sum = j * j * j;
		} while (sum <= n);
	}
	for (int i = 0; i < t; i++)
	{
		printf("%d\n", num[i] - 1);
	}

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int t[500000];

int main()
{
    int T; scanf("%d ", &T);
    for(int i = 0; i < T; i++){
        long long a; scanf("%lld", &a);
        int ans = 0, t1 = 0, t2 = 0;
        t[0] = 1;
        for(long long j = 1; j*j <= a; j++){
            if(j*j*j <= a){
                ans++;
                t[t1++] = j*j*j;
            }
            if(j*j >= t[t2]){
                if(j*j > t[t2]){
                    ans++;
                }
                t2++;
            }
            else ans++;
        }
        printf("==%d\n", ans);
    }
//    while(T--){
//        int n; scanf("%d", &n);
//
//    }
    return 0;
}


#include<stdio.h>
int main(){
    int i, n;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        int m;
        scanf("%d",&m);
        int p, q;
        int s=0;
        for(p=1;p*p*p<=m;p++){
            for(q=1;q*q<=m;q++){
                if(p*p*p==q*q){
                    s++;
                }
            }
        }
        p=p-1;
        q=q-1;
        printf("%d", p+q-s);
    }
    return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if (m==1)
    {
        printf("%d\n",n-m);
    }
   else
       printf("%d\n",n*(m-1));

}


#include <stdio.h>

int main ()
{

  int a,b;
  scanf("%d %d",&a,&b);
  if(a==1 && b==1)
  printf("0\n");
  else if(a==1 && b==2 || a==2 && b==1)
    printf("1\n");
  else
    printf("%d\n",a*(b-1));

  return 0;
}


#include<stdio.h>

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    if(m>1)
        printf("%d",n*(m-1));
    if(m==1)
         printf("%d",(n-1)*m);
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    int a, b, count;
    scanf("%d %d", &a, &b);

    if(b == 1)
    {
        count = (a*b)-b;
    }
    else{
        count = (a*b)-a;
    }

    printf("%d\n", count);

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    long long int n,m,i,j,k=1,sum=0;
    scanf("%lld %lld",&n,&m);
    long long int a[m*n+1];
    if(n<m){
    sum=(m-1)*n;
    printf("%lld",sum);
    }
    else
    {
        sum=m*n-1;

    printf("%lld",sum);
    }

    return 0;
}


#include<stdio.h>

int main() {
    int m,n;
    scanf("%d%d",&n,&m);
    if(m>=2)
    {
        printf("%d",(m-1)*n);
    }
    else
    {
        printf("%d",n-1);
    }

}


#include<stdio.h>
int main()
{
    long long int n,m;
    scanf("%lld%lld",&n,&m);
    long long int ans;

    if(n==1 && m==1)
        ans=0;
    else if(n==1)
        ans=m-1;
    else if(m==1)
        ans=n-1;
    else
        ans=(m-1)*n;

    printf("%d\n",ans);
    return 0;
}


#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d %d",&a,&b);
if(b==1)
{
c=a-1;
printf("%d",c);
}
else if(a==1)
{
c=b-1;
printf("%d",c);
}
else
{
c=a*(b-1);
printf("%d",c);
}
return 0;
}


#include<stdio.h>
#define ll long long
int main()
{
    ll r,c;
    scanf("%lld%lld",&r,&c);
   if(c==1)
    printf("%d",r-1);
    else
    printf("%d",(c-1)*r);
}


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   int a,b,c,d;

   scanf("%d %d",&a,&b);

    if(b==1){
        c =(a-1);
    printf("%d",c);}
    else { c=a*(b-1);
            printf("%d",c);}

}


#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void swap(int* a, int* b)
{
 int temp = *a;*a = *b; *b = temp;
}

void heapify(int arr[], int N, int i){
    int largest = i;

    int left = 2 * i + 1;
    int right = 2 * i + 2;
    if (left < N && arr[left] > arr[largest])
        largest = left;
    if (right < N && arr[right] > arr[largest])

        largest = right;
    if (largest != i) {

        swap(&arr[i], &arr[largest]);
        heapify(arr, N, largest);
    }
}
void heapSort(int arr[], int N)
{
    for (int i = N / 2 - 1; i >= 0; i--)

        heapify(arr, N, i);
    for (int i = N - 1; i >= 0; i--) {
        swap(&arr[0], &arr[i]);
        heapify(arr, i, 0);
    }
}

void fill(int a[],int n){
for(int i=0;i<n;i++){
scanf("%d",a+i);
}
}
void prt(int a[],int n){
for(int i=0;i<n;i++){
printf("%d ",a[i]);
}
}
int min(int a[],int n){int m=1000000001;
for(int i=0;i<n;i++){
	if(a[i]<m){m=a[i];
	}
}return m;
}
int max(int a[],int n){int m=0;
for(int i=0;i<n;i++){
	if(a[i]>m){m=a[i];
	}
}return m;
}
int id(int a[],int n){
for(int i=0;i<n-1;i++){
	if(a[i]!=a[i+1]){return 0;
	}
}return 1;
}

int main(){
int t,n,m;
scanf("%d%d",&n,&m);if(m==1){printf("%d",n-1);
}
else{printf("%lld",(m-1)*n);
}
}


#include<stdio.h>
int main()
{
    int r,c,n,i;
    scanf("%d %d",&r,&c);
    n=r*(c-1);
    if(c==1){n=r-1;}
    printf("%d",n);
    return 0;
}


#include<stdio.h>
int main()
{
    long int N, M;
    scanf("%ld%ld", &N, &M);
    printf("%ld\n", (M==1)?(M-1)*N:(N-1)*M);
    return 0;
}


#include <stdio.h>

int main()
{
    long long int n, m;
    scanf("%lld %lld", &n, &m);
    if (n > m) {
        long long int temp = m;
        m = n;
        n = temp;
    }
    printf("%lld", n*(m-1));

    return 0;
}


#include <stdio.h>
#include <string.h>
int main ()
{

    long long int n,m;
    int result;
    scanf("%lld",&n);
    scanf("%lld",&m);

    if(m==1)
        result = n-1;
    else
        result = n*(m-1);

    printf("%d\n",result);

    return 0;
}


#include<stdio.h>
int main()
{
    int n,m,i;
    scanf("%d%d",&n,&m);
    if(m==1)
     i = ((n-1)*m);
    else
        i=(m-1)*n;
    printf("%d",i);
}


#include<stdio.h>
int main()
{
    int m, n, ans;

    scanf("%d %d", &n ,&m);

    if(n==1 && m==1)
        ans=0;
    else if(n==1 && m>1)
        ans=m-1;
    else if(n>1 && m==1)
        ans=n-1;
    else if(n>1 && m>1)
        ans=(m-1)*n;
    printf("%d\n", ans);
}


#include <stdio.h>

int main() {
int m,n;
scanf("%d %d ",&n,&m);
if(m==1)
printf("%d",n-1);
else
printf("%d",(m-1)*n);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    long r;
    if(m>1)r=n*(m-1);
    else r=(n-1)*m;
    printf("%ld\n",r);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    if(m==1)
    if(n==1)printf("0");
    else printf("%d",n-1);
    else printf("%d",n*(m-1));
    return 0;
}


#include<stdio.h>
int main()
{
	long long int m,n,count=0;
	scanf("%lld%lld",&n,&m);
	// for(int i=0;i<n;i++)
	// {
	// 	for(int j=0;i<m-1;j++)
	// 	{
	// 		count++;
	// 	}

	// }
	if(n==2&&m==1)
	count=1;
	else
	count=n*(m-1);

	printf("%lld",count);
return 0;
}


#include <stdio.h>

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    int answer;

    if(m==1){
        answer = n-1;
        printf("%d", answer);
    }
    else{
        answer = n * (m-1);
        printf("%d", answer);
    }
}


#define __USE_MINGW_ANSI_STDIO 0
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int main()
{
       int n,m,ans;
    scanf("%d %d",&n,&m);
    if(n==1)
        ans=m-1;
    else if(m==1)
        ans=n-1;
    else
    {
        ans=(m*n)-n;
    }
    printf("%d\n",ans);

    return 0;
}


#include<stdio.h>

int main()
{
    long long int ans,n,m;
    scanf("%lld%klld",&n,&m);
    if(m>1)
        ans=(m-1)*n;
    else if(m==1 && n==1)
        ans=0;
    else
        ans=n-1;

    printf("%lld\n",ans);
    return 0;
}


#include <stdio.h>

int main() {
    long long int n,m;
    scanf("%d %d", &n, &m);
    if(m==1){
        printf("%d\n",n-1);
    }
    else{
        printf("%d\n",(m-1)*(n));
    }
    return 0;
}


#include<stdio.h>

int main(){
    int n,m;
    scanf("%d %d", &n,&m);
    if(m == 1){
        printf("%d", n-1);
    }else {
        printf("%d", ((m-1)*n));
    }
}


#include<stdio.h>
int main()
{
   int N,M;
   scanf("%d%d",&N,&M);
    if (M==1)
    {
        printf("%lld\n",N-M);
    }
    else
   printf("%d\n",(N*M)-N);
 return 0;
}


#include <stdio.h>
int main(void)
{
    long long int n,m;
    scanf("%d %d",&n,&m);
	long long int out;
	if(m==1) out=n-1;
	else out=(m-1)*n;
	printf("%d",out);
}


#include<stdio.h>
int main()
{
    long n, m;
    scanf("%d %d", &n, &m);
    if(m%2==0)
    {
        printf("%ld\n", (m-1)*(m-1));
    }
    else
    {
        printf("%ld\n", m*m);
    }
    return 0;
}


#include<math.h>
#include<stdio.h>
int main(){
	   int n,m;
	   scanf("%d%d",&n,&m);
	   if(n==1||m==1) printf("%d\n",n*m-1);
	   else{
		printf("%d\n",n*(m-1));
	   }
     return 0;
}


#include<stdio.h>
int main()
{
    int N, M; scanf("%d %d", &N, &M);
    if(M == 1) printf("%d", N - 1);
    else printf("%d", N * (M - 1));
}


#include<stdio.h>

int main()
{
    int N, M, num;
    scanf("%d %d", &N, &M);
    if(M < 2) {
        num = (N-1)*M;
    }
    else {
        num = (M-1)*N;
    }
    printf("%d\n", num);
    return 0;
}


#include<stdio.h>
int main()
{
   long long int n,m;
  long long int sum = 0;
   INPUT:
   scanf("%lld%lld",&n,&m);
   if(n>=1&&m>=1&&n<=1000000000&&m<=1000000000){
   sum=(m-1)*n;
   printf("%lld",sum);
   }
   else
   {
       goto INPUT;
   }
}


#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(b==1)
    {
        printf("%d",a-1);
        return 0;
    }
    if(a==1)
    {
        printf("%d",b-1);
        return 0;
    }
    printf("%d",(b-1)*a);
    return 0;
}


#include <stdio.h>
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    if(m==1) {
        printf("%d",n-1);
    }
    else {
        printf("%d",(m-1)*n);
    }
}


#include <stdio.h>

int main(void) {
	// your code goes here
	int n,m;
	scanf("%d%d",&n,&m);
	if (m==1)
	{
	    printf("%d",n-1);
	}
	else
	{
	    printf("%d",(m-1)*n);
	}
	return 0;
}


#include <stdio.h>

int
main(void)
{
	int n, m;

	scanf("%d %d", &n, &m);

	if (m == 1)
		printf("%d\n", n - 1);
	else
		printf("%d\n", n * (m - 1));

	return 0;
}


#include <stdio.h>

int main(){
  int n,m;
  scanf("%d %d",&n,&m);
  if(m!=1){
    printf("%d",n*(m-1));
  }else{
    printf("%d",n-1);
  }
  return 0;
}


#include <stdio.h>

int main(void)
{
    int r, c;
    scanf("%i %i", &r, &c);
    if (c == 1)
    {
        printf("%i\n", r - 1);
    }
    else
    {
        printf("%i\n", r * (c - 1));
    }
}


#include<stdio.h>
int main()
{
    int i,j;
    scanf("%d%d",&i,&j);
    if(i==1&&j==1)
    {
        printf("0\n");
    }
    else if(j==1)
    {
        printf("%d\n",i-1);
    }
    else
    {
        printf("%d\n",i*(j-1));
    }
}


#include<stdio.h>
int main()
{
   int a,b;
   scanf("%d%d",&a,&b);

   if(b!=1)

   printf("%d",(a*b)-a);

   else
   printf("%d",a-b);

   return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
       long long int a,b;
       scanf("%lld %lld",&a,&b);

       if(a<=b){
        printf("%lld",((b-1)*a));
       }

       else{
        printf("%lld",((a-1)*b));
       }
       return 0;
}


#include<stdio.h>
int main()
{
    int M,N;
    scanf("%d%d",&N,&M);
    if(M==1){
        printf("%d",N-1);
    }
    else{
        printf("%d",(M-1)*N);
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int c, r;
    scanf("%d %d", &r, &c);
    if(c==1)
        printf("%d\n", r-1);
    else
        printf("%d\n", (c-1)*r);
    return 0;
}


#include <stdio.h>

int main()
{int m,n;
scanf("%d%d",&n,&m);
if(m!=1){printf("%d",(m-1)*n);}
else{printf("%d",n-1);}

    return 0;
}


#include<stdio.h>
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    if(m==1){
        printf("%d\n",n-1);
    }
    else{
        printf("%d\n",(m-1)*n);
    }
    return 0;
}


#include<stdio.h>
int main()
{
long long m,n;
scanf("%lld%lld",&m,&n);
printf("%lld\n",m*(n-1));
return 0;
}


#include<stdio.h>
int main(){
int a,b;
scanf("%d%d",&a,&b);
if(b==1){
printf("%d\n",(a-1));

}
else{
printf("%d\n",(b-1)*a);

}

}


#include<stdio.h>
int main()
{
    long long n,m,s;
    scanf("%lld%lld",&n,&m);
    if(n>m)
    {
        n--;
    }
    else
    {
        m--;
    }
    printf("%lld",n*m);
    return 0;
}


#include <stdio.h>

#define ll long long

int main()
{
    ll  m;
    ll  n;
    ll  k;
    ll  i;
    ll  j;

    i = -1;
    ll ret = 0;
    scanf("%lld %lld", &n, &m);
    if (n == 1)
        ret = m - 1;
    else if (m == 1)
        ret = n - 1;
    else if (n == 2 && m == 2)
        ret = 4;
    else
        ret = n * (m - 1);
    printf("%lld\n", ret);
}


#include<stdio.h>
int main()
{
    int r,c;
    scanf("%d %d",&r,&c);
    if(c>1){
        printf("%d", r*(c-1));
    }
    else printf("%d", r-1);

    return 0;
}


#define __USE_MINGW_ANSI_STDIO 0
#include <stdio.h>

#define maxN 200000

#define MOD 1000000007

// MODULAR NCR
// DEPENDENCIES:

// nCr % mod function
// Using Fermat's Little theorem: a^(p-2) = a^(-1) (mod p)

// Build factorial array
long long fac[maxN + 1];
void __attribute__((constructor))
initFacs() {
	fac[0] = 1;
    for (int i = 1; i <= maxN; i++) fac[i] = fac[i - 1] * i % MOD;
}

// Calculate base ^ pow % mod
long long modPower(long long base, int pow, int mod)
{
    long long res = 1;
    base %= mod;
    // constantly decompose base ^ pow = (base ^ 2) ^ (pow / 2)
    while (pow > 0) {
        // make sure if it is odd, then base ^ pow = base ^ (pow - 1) * base
        if (pow % 2 == 1) res = res * base % mod;
        pow /= 2;
        base = (base * base) % mod;
    }
    return res;
}

// a ^ (p - 2) = a ^ (-1) (mod p)
long long modInverse(long long n, int mod) {
    return modPower(n, mod - 2, mod);
}

// nCr = n! / r! / (n - r)!
// nCr = n! * inv(r!) * inv((n - r)!)
long long nCrModP(unsigned long long n, int r, int mod) {
    // Base cases
    if (n < r) return 0;
    if (r == 0) return 1;

    return fac[n] * modInverse(fac[r], mod) % mod
           * modInverse(fac[n - r], mod) % mod;
}
// END MODULAR NCR

void testcase() {
	int n, k;
	scanf("%d%d", &n, &k);
	long long T;
	long long ans;
	if (n % 2 == 1) {
		// n odd
		T = 1;
		for (int i = 0; i <= (n - 1) / 2; ++i) {
			T += nCrModP(n, i, MOD);
			T %= MOD;
		}
		ans = 1;
		for (int i = 0; i < k; ++i) {
			ans *= T;
			ans %= MOD;
		}
	} else {
		// n even
		T = 0;
		for (int i = 0; i < n / 2; ++i) {
			T += nCrModP(n, 2 * i, MOD);
			T %= MOD;
		}
		if (T == 1) {
			ans = k + 1;
		} else {
			// GP, T != 1
			ans = modPower(T, k + 1, MOD);
			ans -= 1;
			ans *= modInverse(T - 1, MOD);
			ans %= MOD;
		}
	}
	printf("%lld\n", ans);
    return;
}

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; ++i) testcase();
    return 0;
}