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 k cards. After looking at their cards, each player places them face down in a row on the table. Adam's cards are numbered 1 to k from his left, and Eve's cards are numbered 1 to k from her right, so Eve's i-th card lies directly opposite Adam's i-th card.
The cards are turned face up, and for each i∈{1,…,k} points are awarded as follows:
One card beats another according to these rules:
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.
The first line contains a single positive integer N, the number of test cases. Each test case is given on three lines:
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
For each test case, output a single line containing the number of points Eve scores when she arranges her cards optimally.