$\space \space$*A finer blade has never been crafted by my hand. I only hope it does not come too late... A gryphon rider brought word to me only moments ago... ...King Terenas is dead, lads. Killed by Arthas' own hand. You have my condolences. And though they won't bring back your king... Perhaps this blade will administer some justice, return some semblance o' order to the turmoil that grips your kingdom. Terenas was a good man, wise and just. Know that the dwarves o' Ironforge will mourn his passing.*
$\space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space \space $ *—— 《Birth of Ashbringer》*
The subway of Ironforge can been seen as a chain of $n \geq 2$ vertices. In other words, for each $i=1,2,3...n-1$, there is an edge between vertex $i$ and vertex $i+1$.
There is a number $a_i(1 \leq i\leq n)$ on vertex $i$ and a prime number $b_i(1\leq i < n)$ written on the edge between vertex $i$ and vertex $i+1$.
You may start a trip on some vertex with an empty bag. When you are on vertex $i$, you can put all prime factors of $a_i$ into your bag. You can walk through an edge with prime number $p$ written on it if and only if you already have $p$ in your bag. You are allowed to pass each vertex and each edge **multiple times**.
You need to answer $m$ queries. In each query you are given two numbers $x,y$. You need to answer whether you can reach vertex $y$ if you start your trip on vertex $x$ by the subway of Ironforge.