#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  unsigned testcases;
  scanf("%u", &testcases);

  while (testcases--) {
    unsigned kids, kinds, cards_num;
    scanf("%u %u %u", &kids, &kinds, &cards_num);

    map<string, unsigned> cards;
    for (unsigned i = 0; i < kinds; ++i) {
      char str[11];
      scanf("%s", str);
      cards[str];
    }

    for (unsigned i = 0; i < cards_num; ++i) {
      char str[11];
      scanf("%s", str);
      if (auto it = cards.find(str); it != cards.end())
        it->second++;
    }

    unsigned long long result = 0;
    for (const auto& c : cards)
      if (c.second < kids)
        result += kids - c.second;

    printf("%llu\n", result);
  }
}
