#include <bits/stdc++.h>
using namespace std;
const int maxn = 1300005;
const int maxc = 18;
int R[maxn], L[maxn], U[maxn], D[maxn], Row[maxn];
int S[maxc];
int Col[maxn];
int deep, ans[maxn];
string s1[20], s2[20];
int aa[20], bb[20], n, m;
void remove(int &c) {
  L[R[c]] = L[c];
  R[L[c]] = R[c];
  for (int i = D[c]; i != c; i = D[i]) {
    for (int j = R[i]; j != i; j = R[j]) {
      U[D[j]] = U[j];
      D[U[j]] = D[j];
      S[Col[j]]--;
    }
  }
}
void resume(int &c) {
  for (int i = U[c]; i != c; i = U[i]) {
    for (int j = L[i]; j != i; j = L[j]) {
      ++S[Col[j]];
      U[D[j]] = j;
      D[U[j]] = j;
    }
  }
  L[R[c]] = c;
  R[L[c]] = c;
}
bool dfs() {
  if (R[0] == 0) {
    cout << "YES" << endl;
    for (int i = 0; i < deep; i++) {
      int low = ans[i] % 100;
      int high = ans[i] / 100, nm[20], nmc = 0;
      for (int i = 0; i < n; i++)
        if (high & (1 << i)) nm[nmc++] = i;
      cout << s1[nm[0]];
      for (int i = 1; i < nmc; i++) cout << "+" << s1[nm[i]];
      cout << "->" << s2[low] << endl;
    }
    return true;
  }
  int i, j;
  int idx, minnum = 999999;
  for (i = R[0]; i != 0; i = R[i]) {
    if (S[i] < minnum) {
      minnum = S[i];
      idx = i;
    }
  }
  remove(idx);
  for (i = D[idx]; i != idx; i = D[i]) {
    ans[deep++] = Row[i];
    for (j = R[i]; j != i; j = R[j]) {
      remove(Col[j]);
    }
    if (dfs()) {
      return true;
    }
    deep--;
    for (j = L[i]; j != i; j = L[j]) {
      resume(Col[j]);
    }
  }
  resume(idx);
  return false;
}
void add(int c, int nd) {
  D[U[c]] = nd;
  U[nd] = U[c];
  D[nd] = c;
  U[c] = nd;
  S[c]++;
  Col[nd] = c;
}
map<string, int> mp;
void init() {
  mp["H"] = 1;
  mp["He"] = 2;
  mp["Li"] = 3;
  mp["Be"] = 4;
  mp["B"] = 5;
  mp["C"] = 6;
  mp["N"] = 7;
  mp["O"] = 8;
  mp["F"] = 9;
  mp["Ne"] = 10;
  mp["Na"] = 11;
  mp["Mg"] = 12;
  mp["Al"] = 13;
  mp["Si"] = 14;
  mp["P"] = 15;
  mp["S"] = 16;
  mp["Cl"] = 17;
  mp["Ar"] = 18;
  mp["K"] = 19;
  mp["Ca"] = 20;
  mp["Sc"] = 21;
  mp["Ti"] = 22;
  mp["V"] = 23;
  mp["Cr"] = 24;
  mp["Mn"] = 25;
  mp["Fe"] = 26;
  mp["Co"] = 27;
  mp["Ni"] = 28;
  mp["Cu"] = 29;
  mp["Zn"] = 30;
  mp["Ga"] = 31;
  mp["Ge"] = 32;
  mp["As"] = 33;
  mp["Se"] = 34;
  mp["Br"] = 35;
  mp["Kr"] = 36;
  mp["Rb"] = 37;
  mp["Sr"] = 38;
  mp["Y"] = 39;
  mp["Zr"] = 40;
  mp["Nb"] = 41;
  mp["Mo"] = 42;
  mp["Tc"] = 43;
  mp["Ru"] = 44;
  mp["Rh"] = 45;
  mp["Pd"] = 46;
  mp["Ag"] = 47;
  mp["Cd"] = 48;
  mp["In"] = 49;
  mp["Sn"] = 50;
  mp["Sb"] = 51;
  mp["Te"] = 52;
  mp["I"] = 53;
  mp["Xe"] = 54;
  mp["Cs"] = 55;
  mp["Ba"] = 56;
  mp["La"] = 57;
  mp["Ce"] = 58;
  mp["Pr"] = 59;
  mp["Nd"] = 60;
  mp["Pm"] = 61;
  mp["Sm"] = 62;
  mp["Eu"] = 63;
  mp["Gd"] = 64;
  mp["Tb"] = 65;
  mp["Dy"] = 66;
  mp["Ho"] = 67;
  mp["Er"] = 68;
  mp["Tm"] = 69;
  mp["Yb"] = 70;
  mp["Lu"] = 71;
  mp["Hf"] = 72;
  mp["Ta"] = 73;
  mp["W"] = 74;
  mp["Re"] = 75;
  mp["Os"] = 76;
  mp["Ir"] = 77;
  mp["Pt"] = 78;
  mp["Au"] = 79;
  mp["Hg"] = 80;
  mp["Tl"] = 81;
  mp["Pb"] = 82;
  mp["Bi"] = 83;
  mp["Po"] = 84;
  mp["At"] = 85;
  mp["Rn"] = 86;
  mp["Fr"] = 87;
  mp["Ra"] = 88;
  mp["Ac"] = 89;
  mp["Th"] = 90;
  mp["Pa"] = 91;
  mp["U"] = 92;
  mp["Np"] = 93;
  mp["Pu"] = 94;
  mp["Am"] = 95;
  mp["Cm"] = 96;
  mp["Bk"] = 97;
  mp["Cf"] = 98;
  mp["Es"] = 99;
  mp["Fm"] = 100;
}
int main() {
  init();
  while (cin >> n >> m) {
    deep = 0;
    for (int i = 0; i < n; i++) {
      cin >> s1[i];
      aa[i] = mp[s1[i]];
    }
    for (int i = 0; i < m; i++) {
      cin >> s2[i];
      bb[i] = mp[s2[i]];
    }
    int cnt;
    for (cnt = 0; cnt <= n + m; cnt++) {
      L[cnt] = cnt - 1;
      R[cnt] = cnt + 1;
      U[cnt] = D[cnt] = cnt;
      Col[cnt] = 0;
    }
    cnt = L[0] = n + m;
    R[n + m] = 0;
    int tad[20], tcnt, tsm;
    for (int t = 0; t < m; t++)
      for (int i = 1; i < (1 << n); i++) {
        tcnt = tsm = 0;
        for (int j = 0; j < n; j++)
          if (i & (1 << j)) {
            tsm += aa[j];
            tad[tcnt++] = j;
          }
        if (tsm == bb[t]) {
          for (int u = cnt + 1; u <= cnt + tcnt + 1; u++) {
            L[u] = u - 1;
            R[u] = u + 1;
            Row[u] = t + i * 100;
          }
          L[cnt + 1] = cnt + tcnt + 1;
          R[cnt + tcnt + 1] = cnt + 1;
          for (int k = 1; k <= tcnt; k++) {
            add(tad[k - 1] + 1, cnt + k);
          }
          add(n + t + 1, cnt + tcnt + 1);
          cnt += tcnt + 1;
        }
      }
    deep = 0;
    if (!dfs()) cout << "NO" << endl;
  }
  return 0;
}
