JOI Laboratory has poisonous snakes. The snakes are numbered . Each snake is divided into parts from the head to the tail. The color of each part is either blue or red. For the poisonous snake , let () be the binary expression of . Then,
- if , the color of the -th part of the poisonous snake from the head is blue, and
- if , the color of the -th part of the poisonous snake from the head is red.
Each poisonous snake has an integer between and , inclusive, called the toxicity. A string of length consisting of is given. The -th character () is the toxicity of the poisonous snake .
Since poisonous snakes are quick, they often escape from JOI Laboratory. Complaints are given to JOI Laboratory by people living near the laboratory who saw poisonous snakes escaping from the laboratory.
You are given a list of complaints for days. The complaints for the -th day () is a string of length consisting of 0
, 1
, ?
.
- If the -th character () of is
0
, this means the -th part of every poisonous snake escaping from the laboratory on the -th day is blue, - If the -th character () of is
1
, this means the -th part of every poisonous snake escaping from the laboratory on the -th day is red, and - If the -th character () of is
?
, this means no information was given by people concerning the -th part of poisonous snakes escaping from the laboratory on the -th day.
All the complaints are precise information. All the poisonous snakes escaping from the laboratory were kept by the staff of JOI Laboratory on the same day. It may happen that the same snake escapes on a different day.
In order to estimate the risk of escaping poisonous snakes, Professor K, the executive director of JOI Laboratory, wants to know the sum of toxicities of the snakes which might escape from the laboratory. Your task is to write a program which calculates, given the list of complaints for days, the sum of toxicities of the snakes which might escape from the laboratory for each day.
Input Specification
The first line contains two space separated integers . They are the number of parts of each poisonous snake and the number of days for the complaints, respectively.
The second line contains a string of length . It describes the toxicities of the poisonous snakes.
Each of the following lines contains a string of length . It is the complaints of the -th day.
Output Specification
Write lines to the standard output. The -th line should contain an integer, the sum of toxicities of the snakes which might escape from the laboratory on -th day.
Constraints
In all test cases,
- ,
- is a string of length and consists of digits from to
- is a string of length and consists of
0
,1
, and?
.
In test cases, , .
In another test cases, .
In another test cases, .
In another test cases, .
Sample Input 1
3 5
12345678
000
0??
1?0
?11
???
Sample Output 1
1
10
12
12
36
Sample Input 2
4 8
3141592653589793
0101
?01?
??1?
?0??
1?00
01?1
??10
????
Sample Output 2
9
18
38
30
14
15
20
80
Comments