7573: Heart

内存限制:512 MB 时间限制:20 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

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 0 to 20. She has n kinds of danmaku, using the i-th danmaku needs the help of a subset bi of her heart pieces and has aggressivity pi. Suppose A is a subset of her n danmakus. If for any two different kinds of danmaku u,v∈A,u≠v, it guarantees bu∩bv=∅, then we call A 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 A is product of aggressivities of all danmakus belongs to A. Obviously, using spellcard A needs the help of heart pieces. The related pieces subset is S(A)=∪u∈Abu.

Koishi wants to know some details about her spellcards. She will ask m questions, in the i-th question, she wants to know the sum of aggressivities of all her spellcard A whose S(A)=xixi is a subset of heart pieces. You must answer all the questions correctly. modulo 998244353

输入格式

There are only one test case.

First line contains a positive integer n(1≤n≤106), the number of danmakus.

The i-th line of the following n lines contains two non-negative integers pi,bi(0≤pi<998244353,0≤bi<221), describing the i-th danmaku, writing integer bi as binary string will get the subset bi

The following integer contains a positive m(1≤m≤106), the number of questions.

The i-th line of the following m lines contains a non-negative integer xi(0≤xi<221), describing the i-th question.

输出格式

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

输入样例 复制

3
1 1
1 2
1 3
3
1
2
3

输出样例 复制

1
1
2