/* Author: Matt Eastman */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

#define FALSE 0
#define TRUE 1

typedef struct {
  char* name;
  int atomic_num;
} Element;

typedef struct {
  Element** elements;
  int num_elements;
  int atomic_num_sum;
  int obvious;
} Path;

Element* Element_New(char* name, int atomic_num) {
  Element* elem = (Element*)calloc(1, sizeof(Element));
  elem->name = strdup(name);
  elem->atomic_num = atomic_num;
  return elem;
}

void Element_Del(Element* elem) {
  free(elem->name);
  free(elem);
}

Path* Path_New(int num_elements) {
  Path* path = (Path*)calloc(1, sizeof(Path));
  path->elements = (Element**)calloc(num_elements, sizeof(Element*));
  path->num_elements = num_elements;
  return path;
}

void Path_Del(Path* path) {
  /* path does not own the elements themselves */
  free(path->elements);
  free(path);
}

/* Create a new path with elem as elements[0] and the elements of path after that */
Path* Path_Combine(Path* path, Element* elem) {
  Path* new_path;
  if (path == NULL) {
    new_path = Path_New(1);
  } else {
    new_path = Path_New(path->num_elements + 1);
    memcpy(new_path->elements + 1, path->elements, sizeof(Element*) * path->num_elements);
    new_path->atomic_num_sum = path->atomic_num_sum;
    new_path->obvious = path->obvious;
  }
  new_path->elements[0] = elem;
  new_path->atomic_num_sum += elem->atomic_num;
  return new_path;
}

void PrintPath(Path* path) {
  int i;
  if (path == NULL) {
    printf("NULL\n");
  } else if (path->obvious) {
    printf("Too Obvious\n");
  } else {
    for (i = 0; i < path->num_elements; i++) {
      printf("[%s]", path->elements[i]->name);
    }
    printf("\n");
  }
}

int ComparePaths(Path* a, Path* b) {
  if (a->num_elements < b->num_elements) return -1;
  if (a->num_elements > b->num_elements) return 1;
  if (a->atomic_num_sum < b->atomic_num_sum) return -1;
  if (a->atomic_num_sum > b->atomic_num_sum) return 1;
  return 0;
}

Path* FindBestPath(int num_elements, Element** elements, char* word) {
  int i;
  Path* path = NULL;
  Path* child_path;
  Path* elem_path;
  int elem_name_len;
  Element* elem;
  int word_len = strlen(word);

  for (i = 0; i < num_elements; i++) {
    elem = elements[i];
    elem_name_len = strlen(elem->name);
    elem_path = NULL;
    if (strncasecmp(word, elem->name, elem_name_len) == 0) {
      if (elem_name_len == word_len) {
        elem_path = Path_Combine(NULL, elem);
      } else {
        child_path = FindBestPath(num_elements, elements, word + elem_name_len);
        if (child_path != NULL) {
          elem_path = Path_Combine(child_path, elem);
          Path_Del(child_path);
        }
      }
    }
    if (elem_path == NULL) {
      continue;
    }
    if (path == NULL) {
      path = elem_path;
      continue;
    }

    switch (ComparePaths(elem_path, path)) {
      case -1:
        Path_Del(path);
        path = elem_path;
        break;
      case 0:
        Path_Del(elem_path);
        path->obvious = TRUE;
        break;
      default:
        Path_Del(elem_path);
    }
  }

  return path;
}

int main(int argc, char** argv) {
  int num_cases, num_elements, num_words;
  int i, j;
  char buf[1024];
  Element** elements;
  Path* path;

  assert(scanf(" %d", &num_cases) == 1);
  for (i = 0; i < num_cases; i++) {
    assert(scanf(" %d", &num_elements) == 1);
    elements = (Element**)calloc(num_elements, sizeof(Element*));
    for (j = 0; j < num_elements; j++) {
      assert(scanf(" %s", buf) == 1);
      elements[j] = Element_New(buf, j);
    }
    assert(scanf(" %d", &num_words) == 1);
    for (j = 0; j < num_words; j++) {
      assert(scanf(" %s", buf) == 1);
      path = FindBestPath(num_elements, elements, buf);
      assert(path != NULL);
      PrintPath(path);
      Path_Del(path);
    }
    for (j = 0; j < num_elements; j++) {
      Element_Del(elements[j]);
    }
    free(elements);
  }
  return 0;
}
