For N number of alphabet pairs(in upper or lower case), count the occurrence of the given alphabet pairs in a string S of size M. Output the number of pairs found in the string S, out of total N pairs.

Note: Finding the pair means finding both the characters in a particular pair in the string.

**Input:**

First line of input is an integer T, denoting the number of test cases. For each test case, enter two integers N and M on the same line, denoting the number of pairs of alphabets to be searched for and the size of the string S, respectively. Next line of input comprises of the N alphabet pairs separated by a single space in between. The last line of input comprises of the string S of size M.

**Output:**

The only line of output for each test case is an integer that tells the number of pairs (<=N) that occured in the string S. If no pair is found, the output will be zero.

**Constraints:**

1<=T<=100

1<=N<=10

2<=M<=20

**Example:
Input:**

3

3 5

A G d i P o

APiod

1 3

r e

ghe

3 6

F E n O F s

FOrnEs

2

0

3

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

murli01 | 343 |

decoder_101 | 274 |

john_wick | 204 |

singhalsaurav1997 | 196 |

Sulagna | 189 |

john_wick | 725 |

PiyushPandey4 | 717 |

ASWATHAMA | 565 |

akhyasharma01 | 547 |

decoder_101 | 512 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.