(function(stdin) {
  var lines = stdin.trim().split('\n');
  while (1) {
    var n = Number(lines.shift().trim());
    if (n === 0) {
      break;
    }
    var table = {};
    for (var i = 0; i < n; i++) {
      var conv = lines.shift().trim().split(/\s/);
      table[conv[0]] = conv[1];
    }
    var m = Number(lines.shift().trim());
    var result = '';
    for (var j = 0; j < m; j++) {
      var value = lines.shift().trim();
      if (table[value]) {
        result += table[value];
      } else {
        result += value;
      }
    }
    console.log(result);
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));