#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
string getName(int id) {
  for (map<string, int>::iterator i = mp.begin(); i != mp.end(); i++) {
    if (i->second == id) return i->first;
  }
}
string name[20], final[20];
const int N = 17;
const int MAXR = (1 << 17);
const int MAXC = N + N;
const int TOTAL = (MAXR + 1) * (MAXC + 1);
const int MAXV = 0x3F3F3F3F;
pair<int, int> state[MAXR];
int n, m, mat[MAXR][MAXC];
int cid[TOTAL], rid[TOTAL], s[MAXC];
int res[MAXR];
int l[TOTAL], r[TOTAL], u[TOTAL], d[TOTAL];
int lastc[MAXC];
void remove(const int& col) {
  l[r[col]] = l[col];
  r[l[col]] = r[col];
  for (int i = d[col]; i != col; i = d[i]) {
    for (int j = r[i]; j != i; j = r[j]) {
      d[u[j]] = d[j];
      u[d[j]] = u[j];
      s[cid[j]]--;
    }
  }
}
void resume(const int& col) {
  for (int i = u[col]; i != col; i = u[i]) {
    for (int j = l[i]; j != i; j = l[j]) {
      d[u[j]] = j;
      u[d[j]] = j;
      s[cid[j]]++;
    }
  }
  l[r[col]] = col;
  r[l[col]] = col;
}
inline void addlr(const int& ln, const int& rn) {
  l[r[ln]] = rn;
  r[rn] = r[ln];
  r[ln] = rn;
  l[rn] = ln;
}
inline void addud(const int& un, const int& dn) {
  u[d[un]] = dn;
  d[dn] = d[un];
  d[un] = dn;
  u[dn] = un;
}
bool dfs(int k) {
  if (r[0] == 0) {
    puts("YES");
    int mystate, myid;
    for (int i = 1; i < k; i++) {
      int w = 0;
      mystate = state[res[i]].first;
      myid = state[res[i]].second;
      for (int j = 0; j < n; j++) {
        if (mystate & (1 << j)) {
          if (w++) putchar('+');
          cout << name[j];
        }
      }
      cout << "->" << final[myid] << "\n";
    }
    return true;
  }
  int c, minv = MAXV;
  for (int i = r[0]; i != 0; i = r[i]) {
    if (s[i] < minv) {
      minv = s[i];
      c = i;
    }
  }
  if (minv == 0) return false;
  remove(c);
  for (int i = d[c]; i != c; i = d[i]) {
    res[k] = rid[i];
    for (int j = r[i]; j != i; j = r[j]) remove(cid[j]);
    if (dfs(k + 1)) return true;
    for (int j = l[i]; j != i; j = l[j]) resume(cid[j]);
  }
  resume(c);
  return false;
}
void adapt(int n, int m) {
  memset(s, 0, sizeof(s));
  l[0] = r[0] = 0;
  for (int i = 1; i <= m; i++) {
    addlr(i - 1, i);
    u[i] = d[i] = i;
    lastc[i] = i;
  }
  int ind = m + 1;
  for (int i = 1; i <= n; i++) {
    bool isfirst = true;
    for (int j = 1; j <= m; j++) {
      if (mat[i][j]) {
        if (isfirst) {
          isfirst = false;
          l[ind] = r[ind] = ind;
        } else {
          addlr(ind - 1, ind);
        }
        addud(lastc[j], ind);
        lastc[j] = ind;
        rid[ind] = i;
        cid[ind] = j;
        s[j]++;
        ind++;
      }
    }
  }
}
int main() {
  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;
  while (cin >> n >> m) {
    memset(mat, 0, sizeof(mat));
    for (int i = 0; i < n; i++) cin >> name[i];
    for (int i = 1; i <= m; i++) cin >> final[i];
    int r = 0;
    for (int i = 1; i < (1 << n); i++) {
      int total = 0;
      for (int j = 0; j < n; j++) {
        if (i & (1 << j)) total += mp[name[j]];
      }
      string fuck = getName(total);
      for (int j = 1; j <= m; j++) {
        if (fuck == final[j]) {
          r++;
          state[r] = make_pair(i, j);
          mat[r][j] = 1;
          for (int k = 0; k < n; k++) {
            if (i & (1 << k)) {
              mat[r][m + k + 1] = 1;
            }
          }
        }
      }
    }
    adapt(r, m + n);
    if (!dfs(1)) puts("NO");
  }
  return 0;
}
