#P7840. Heart

Heart

Heart

Problem Description

Notice:Don't output extra spaces at the end of one line. Koishi loves her heart. Koishi's heart are divided into 21 pieces, indexed from 00 to 2020. She has nn kinds of danmaku, using the ii-th danmaku needs the help of a subset bib_i of her heart pieces and has aggressivity pip_i. Suppose AA is a subset of her nn danmakus. If for any two different kinds of danmaku u,vA,uvu,v\in A,u\neq v, it guarantees bubv=b_u\cap b_v=\emptyset, then we call AA a spellcard(because danmaku in the same spellcard must be released simultaneously, and one piece of heart can only supply one kind of damaku at the same time). The aggressivity of the spellcard AA is product of aggressivities of all danmakus belongs to AA. Obviously, using spellcard AA needs the help of heart pieces. The related pieces subset is S(A)=uAbuS(A)=\cup_{u\in A}b_u. Koishi wants to know some details about her spellcards. She will ask mm questions, in the ii-th question, she wants to know the sum of aggressivities of all her spellcard AA whose S(A)=xiS(A)=x_i, xix_i is a subset of heart pieces. You must answer all the questions correctly. modulo 998244353

Input

There are only one test case. First line contains a positive integer n(1n106)n(1\leq n\leq 10^6), the number of danmakus. The ii-th line of the following nn lines contains two non-negative integers pi,bi(0pi<998244353,0bi<221)p_i,b_i(0\leq p_i<998244353,0\leq b_i<2^{21}), describing the ii-th danmaku, writing integer bib_i as binary string will get the subset bib_i The following integer contains a positive m(1m106)m(1\leq m\leq 10^6), the number of questions. The ii-th line of the following mm lines contains a non-negative integer xi(0xi<221)x_i(0\leq x_i<2^{21}), describing the ii-th question.

Output

Output mm lines, and the ii-th line should contain a non-negative integer as the answer of the ii-th question

Sample Input

3
1 1
1 2
1 3
3
1
2
3

Sample Output

1
1
2

Source

2020 Multi-University Training Contest 7