import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict from functools import lru_cache from typing import List # for AtCoder Easy test if __file__ == 'prog.py': pass else: sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') input = sys.stdin.readline def readints(): return map(int, input().split()) def readlist(): return list(readints()) def readstr(): return input()[:-1] class SCC: def __init__(self, N, E): self.N = N self.E = E self.I = [[] for _ in range(N)] for s in range(N): for t in E[s]: self.I[t].append(s) self.V = [] self.cid = [None] * N self.c_num = 0 self.traverse() self.traverse2() self.C = [[] for _ in range(self.c_num)] for i in range(self.N): c = self.cid[i] self.C[c].append(i) def traverse(self): flag = [False] * self.N for i in range(self.N): if flag[i] is False: self.dfs(i, flag) self.V.reverse() def traverse2(self): flag = [False] * self.N cid = 0 for v in self.V: if flag[v] is False: self.dfs2(v, flag) self.c_num += 1 def dfs(self, v, flag): stack = [~v, v] while stack: v = stack.pop() if v < 0: self.V.append(~v) continue if flag[v] is True: stack.pop() continue flag[v] = True for dest in self.E[v]: if flag[dest] is False: stack.append(~dest) stack.append(dest) def dfs2(self, v, flag): stack = [v] while stack: v = stack.pop() if flag[v] is True: continue flag[v] = True self.cid[v] = self.c_num for dest in self.I[v]: if flag[dest] is False: stack.append(dest) class TwoSat: def __init__(self, N: int): self.N = N self.E = [[] for _ in range(2 * N)] def vid(self, n): return 2 * (~n) + 1 if n < 0 else 2 * n def add_clause(self, s: int, t: int) -> None: def oppose(id): return id ^ 1 sid, tid = self.vid(s), self.vid(t) # ~s -> t self.E[oppose(sid)].append(tid) # ~t -> s self.E[oppose(tid)].append(sid) def if_then(self, s: int, t: int) -> None: sid, tid = self.vid(s), self.vid(t) self.E[sid].append(tid) def solve(self) -> List[bool]: cid = SCC(2 * self.N, self.E).cid for i in range(self.N): if cid[2 * i] == cid[2 * i + 1]: return None # if cid[2 * a] > cid[2 * a + 1], possibly ~a -> a ans = [cid[2 * i] > cid[2 * i + 1] for i in range(self.N)] return ans class PrimeTable: def __init__(self, N): self.is_prime = [True] * (N + 1) self.is_prime[0] = False self.is_prime[1] = False for i in range(2, N + 1): if i * i > N: break if self.is_prime[i] is False: continue for j in range(2, N + 1): if i * j > N: break self.is_prime[i * j] = False self.primes = [n for n in range(2, N + 1) if self.is_prime[n]] N = int(input()) is_prime = PrimeTable(10 ** 6).is_prime A = [] for _ in range(N): a, b = readints() A.append(a) A.append(b) solver = TwoSat(2 * N) for i in range(N): solver.if_then(2 * i, ~(2 * i + 1)) solver.if_then(~(2 * i), 2 * i + 1) solver.if_then(2 * i + 1, ~(2 * i)) solver.if_then(~(2 * i + 1), 2 * i) for i in range(2 * N): for j in range(2 * N): if i // 2 == j // 2: continue n = int(str(A[i]) + str(A[j])) if is_prime[n]: solver.if_then(i, j) solver.if_then(~j, ~i) print('Yes' if solver.solve() is not None else 'No')