#include <bits/stdc++.h>
static inline int popcount(int x) { return __builtin_popcount(x); }
template <class T, class U>
static inline std::pair<T, U> mp(const T& a, const U& b) {
  return std::make_pair(a, b);
}
std::map<std::string, int> S;
std::map<int, std::string> back;
void make_map() {
  S["H"] = 1;
  S["He"] = 2;
  S["Li"] = 3;
  S["Be"] = 4;
  S["B"] = 5;
  S["C"] = 6;
  S["N"] = 7;
  S["O"] = 8;
  S["F"] = 9;
  S["Ne"] = 10;
  S["Na"] = 11;
  S["Mg"] = 12;
  S["Al"] = 13;
  S["Si"] = 14;
  S["P"] = 15;
  S["S"] = 16;
  S["Cl"] = 17;
  S["Ar"] = 18;
  S["K"] = 19;
  S["Ca"] = 20;
  S["Sc"] = 21;
  S["Ti"] = 22;
  S["V"] = 23;
  S["Cr"] = 24;
  S["Mn"] = 25;
  S["Fe"] = 26;
  S["Co"] = 27;
  S["Ni"] = 28;
  S["Cu"] = 29;
  S["Zn"] = 30;
  S["Ga"] = 31;
  S["Ge"] = 32;
  S["As"] = 33;
  S["Se"] = 34;
  S["Br"] = 35;
  S["Kr"] = 36;
  S["Rb"] = 37;
  S["Sr"] = 38;
  S["Y"] = 39;
  S["Zr"] = 40;
  S["Nb"] = 41;
  S["Mo"] = 42;
  S["Tc"] = 43;
  S["Ru"] = 44;
  S["Rh"] = 45;
  S["Pd"] = 46;
  S["Ag"] = 47;
  S["Cd"] = 48;
  S["In"] = 49;
  S["Sn"] = 50;
  S["Sb"] = 51;
  S["Te"] = 52;
  S["I"] = 53;
  S["Xe"] = 54;
  S["Cs"] = 55;
  S["Ba"] = 56;
  S["La"] = 57;
  S["Ce"] = 58;
  S["Pr"] = 59;
  S["Nd"] = 60;
  S["Pm"] = 61;
  S["Sm"] = 62;
  S["Eu"] = 63;
  S["Gd"] = 64;
  S["Tb"] = 65;
  S["Dy"] = 66;
  S["Ho"] = 67;
  S["Er"] = 68;
  S["Tm"] = 69;
  S["Yb"] = 70;
  S["Lu"] = 71;
  S["Hf"] = 72;
  S["Ta"] = 73;
  S["W"] = 74;
  S["Re"] = 75;
  S["Os"] = 76;
  S["Ir"] = 77;
  S["Pt"] = 78;
  S["Au"] = 79;
  S["Hg"] = 80;
  S["Tl"] = 81;
  S["Pb"] = 82;
  S["Bi"] = 83;
  S["Po"] = 84;
  S["At"] = 85;
  S["Rn"] = 86;
  S["Fr"] = 87;
  S["Ra"] = 88;
  S["Ac"] = 89;
  S["Th"] = 90;
  S["Pa"] = 91;
  S["U"] = 92;
  S["Np"] = 93;
  S["Pu"] = 94;
  S["Am"] = 95;
  S["Cm"] = 96;
  S["Bk"] = 97;
  S["Cf"] = 98;
  S["Es"] = 99;
  S["Fm"] = 100;
  S["Md"] = 101;
  for (auto itr = S.begin(); itr != S.end(); itr++)
    back[itr->second] = itr->first;
}
static constexpr int MAXN = 17;
static int dp[1 << MAXN][MAXN];
static std::vector<int> start;
static std::vector<int> end;
static std::map<int, std::vector<int>> sums;
static int solve(int mask, int index) {
  if (index < 0) return popcount(mask) == 0;
  if (popcount(mask) == 0) {
    if (index < 0) return 1;
    return 0;
  }
  int& ref = dp[mask][index];
  if (ref == -1) {
    const std::vector<int>& choices = sums[end[index]];
    ref = 0;
    for (int dumb : choices) {
      bool flag = true;
      for (int i = 0; i < start.size(); i++) {
        if (dumb & (1 << i)) flag = flag && (mask & (1 << i));
        if (!flag) break;
      }
      if (!flag) continue;
      ref = ref || solve(mask & ~dumb, index - 1);
      if (ref) {
        return ref;
      }
    }
  }
  return ref;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  make_map();
  int size1, size2;
  std::cin >> size1 >> size2;
  for (int i = 0; i < size1; i++) {
    std::string next;
    std::cin >> next;
    start.push_back(S[next]);
  }
  for (int i = 0; i < size2; i++) {
    std::string next;
    std::cin >> next;
    end.push_back(S[next]);
  }
  for (int i = 0; i < (1 << size1); i++) {
    int sum = 0;
    for (int j = 0; j < size1; j++) {
      if (i & (1 << j)) {
        sum += start[j];
      }
    }
    for (int j = 0; j < size2; j++) {
      if (end[j] == sum) {
        sums[sum].push_back(i);
        break;
      }
    }
  }
  std::memset(dp, -1, sizeof(dp));
  if (!solve((1 << size1) - 1, size2 - 1)) {
    std::cout << "NO\n";
    return 0;
  }
  std::cout << "YES\n";
  std::vector<std::string> answer;
  int mask = (1 << size1) - 1;
  int index = size2 - 1;
  while (index >= 0) {
    int chosen = -1;
    for (int i : sums[end[index]]) {
      bool flag = true;
      for (int j = 0; j < size1; j++) {
        if (i & (1 << j)) flag = flag && (mask & (1 << j));
        if (!flag) break;
      }
      if (!flag) continue;
      if (solve(mask & ~i, index - 1)) {
        chosen = i;
        break;
      }
    }
    assert(chosen != -1);
    answer.push_back(std::string());
    int sum = 0;
    for (int i = 0; i < size1; i++)
      if (chosen & (1 << i)) answer.back() += back[start[i]] + "+";
    answer.back().pop_back();
    answer.back() += "->" + back[end[index]];
    mask &= ~chosen;
    index--;
  }
  assert(mask == 0 && "You fucked up.");
  for (const std::string& luv : answer) std::cout << luv << '\n';
  return 0;
}
