Card Game Cheater

No attempts yetTime limit1sMemory limit128 MB

Problem

Adam and Eve play a card game with a standard 52-card deck. They sit on opposite sides of a table, facing each other. Each player receives kk cards. After looking at their cards, each player places them face down in a row on the table. Adam's cards are numbered 11 to kk from his left, and Eve's cards are numbered 11 to kk from her right, so Eve's ii-th card lies directly opposite Adam's ii-th card.

The cards are turned face up, and for each i{1,,k}i \in \{1, \dots, k\} points are awarded as follows:

  • If Adam's ii-th card beats Eve's ii-th card, Adam scores one point.
  • If Eve's ii-th card beats Adam's ii-th card, Eve scores one point.

One card beats another according to these rules:

  • A higher value always beats a lower value: a three beats a two, a four beats a two or a three, and so on. An ace beats every card except (possibly) another ace.
  • If two cards have the same value, the suit decides: hearts beat every other suit, spades beat every suit except hearts, diamonds beat only clubs, and clubs beat no suit.

For example, the ten of spades beats the ten of diamonds, but it does not beat the jack of clubs.

This ought to be a game of chance, but lately Eve keeps winning. She is using marked cards: she knows exactly which card Adam has placed at each position before he turns them face up. Using this knowledge, she arranges her own cards to score as many points as possible.

Given Adam's and Eve's cards, determine how many points Eve scores when she plays optimally.

Input

The first line contains a single positive integer NN, the number of test cases. Each test case is given on three lines:

  • a line with a single integer kk (1k261 \le k \le 26), the number of cards each player holds;
  • a line with Adam's kk cards, listed from left to right;
  • a line with Eve's kk cards.

Each card is written as two characters. The first is its value (one of 2 3 4 5 6 7 8 9 T J Q K A) and the second is its suit (C, D, S, or H). Cards on a line are separated by whitespace. For instance, if Adam holds the ten of clubs, the two of hearts, and the jack of diamonds, his line reads:

TC 2H JD

Output

For each test case, output a single line containing the number of points Eve scores when she arranges her cards optimally.