Do you know Just Odd Inventions Co., Ltd? The business of this company is doing "just odd inventions." Here we shall abbreviate its name, and call it the JOI Company.
Recently, the JOI Company is faced with a serious decline in its profitability by doing just odd inventions only. It is planning to start a new business. The plan is to sell liquid containing RNA chains. An RNA chain is considered as a string consisting of characters A
, G
, C
, U
. For its business, the JOI Company prepares chains of RNA.
The JOI Company will accept an order of RNA chains from customers in the following form:
- A customer chooses two strings , . Then, among RNA chains prepared by the JOI Company, it sells strings whose first characters are and last characters are . Here, , are the length of , , respectively.
How many RNA chains prepared by the JOI Company match the conditions of orders from customers?
Given the information on RNA chains prepared by the JOI Company and orders from customers, write a program which calculates the number of RNA chains prepared by the JOI Company which match the conditions of orders from customers.
Input Specification
Read the following data from the standard input.
- The first line of input contains two space separated integers , . This means the JOI Company prepares chains of RNA, and there are orders from customers.
- The -th line () of the following lines contains a string , which is the -th RNA chain prepared by the JOI Company.
- The -th line () of the following lines contains two space separated strings , . This means, in the -th order, the customer chooses two strings , .
Output Specification
The output consists of lines. The -th line () contains an integer, the number of RNA chains prepared by the JOI Company which match the condition of the -th order.
Constraints
All input data satisfy the following conditions.
- .
- .
- Each string consists of characters
A
,G
,C
,U
. - ().
- ().
- ().
- .
- .
- .
Sample Input 1
2 3
AUGC
AGC
G C
AU C
A C
Sample Output 1
0
1
2
Sample Input 2
3 3
AA
AA
AGA
AA AA
AG GA
AG GA
Sample Output 2
2
1
1
Comments