#include <bits/stdc++.h>
using namespace std;
map<string, int> N;
inline void init_N() {
  N["H"] = 1;
  N["He"] = 2;
  N["Li"] = 3;
  N["Be"] = 4;
  N["B"] = 5;
  N["C"] = 6;
  N["N"] = 7;
  N["O"] = 8;
  N["F"] = 9;
  N["Ne"] = 10;
  N["Na"] = 11;
  N["Mg"] = 12;
  N["Al"] = 13;
  N["Si"] = 14;
  N["P"] = 15;
  N["S"] = 16;
  N["Cl"] = 17;
  N["Ar"] = 18;
  N["K"] = 19;
  N["Ca"] = 20;
  N["Sc"] = 21;
  N["Ti"] = 22;
  N["V"] = 23;
  N["Cr"] = 24;
  N["Mn"] = 25;
  N["Fe"] = 26;
  N["Co"] = 27;
  N["Ni"] = 28;
  N["Cu"] = 29;
  N["Zn"] = 30;
  N["Ga"] = 31;
  N["Ge"] = 32;
  N["As"] = 33;
  N["Se"] = 34;
  N["Br"] = 35;
  N["Kr"] = 36;
  N["Rb"] = 37;
  N["Sr"] = 38;
  N["Y"] = 39;
  N["Zr"] = 40;
  N["Nb"] = 41;
  N["Mo"] = 42;
  N["Tc"] = 43;
  N["Ru"] = 44;
  N["Rh"] = 45;
  N["Pd"] = 46;
  N["Ag"] = 47;
  N["Cd"] = 48;
  N["In"] = 49;
  N["Sn"] = 50;
  N["Sb"] = 51;
  N["Te"] = 52;
  N["I"] = 53;
  N["Xe"] = 54;
  N["Cs"] = 55;
  N["Ba"] = 56;
  N["La"] = 57;
  N["Ce"] = 58;
  N["Pr"] = 59;
  N["Nd"] = 60;
  N["Pm"] = 61;
  N["Sm"] = 62;
  N["Eu"] = 63;
  N["Gd"] = 64;
  N["Tb"] = 65;
  N["Dy"] = 66;
  N["Ho"] = 67;
  N["Er"] = 68;
  N["Tm"] = 69;
  N["Yb"] = 70;
  N["Lu"] = 71;
  N["Hf"] = 72;
  N["Ta"] = 73;
  N["W"] = 74;
  N["Re"] = 75;
  N["Os"] = 76;
  N["Ir"] = 77;
  N["Pt"] = 78;
  N["Au"] = 79;
  N["Hg"] = 80;
  N["Tl"] = 81;
  N["Pb"] = 82;
  N["Bi"] = 83;
  N["Po"] = 84;
  N["At"] = 85;
  N["Rn"] = 86;
  N["Fr"] = 87;
  N["Ra"] = 88;
  N["Ac"] = 89;
  N["Th"] = 90;
  N["Pa"] = 91;
  N["U"] = 92;
  N["Np"] = 93;
  N["Pu"] = 94;
  N["Am"] = 95;
  N["Cm"] = 96;
  N["Bk"] = 97;
  N["Cf"] = 98;
  N["Es"] = 99;
  N["Fm"] = 100;
}
string e[17], e2[17];
int n, k, no[17], no2[17], b[17], s[17];
bool found;
void solve(int t) {
  if (t >= n) {
    bool ok = true;
    for (int i = 0; i < k; i++)
      if (s[i] != no2[i]) {
        ok = false;
        break;
      }
    if (ok) found = true;
  } else
    for (int i = 0; i < k; i++)
      if ((s[i] + no[t]) <= no2[i]) {
        s[i] += no[t];
        int tmp = b[t];
        b[t] = i;
        solve(t + 1);
        if (found) return;
        b[t] = tmp;
        s[i] -= no[t];
      }
}
vector<string> r[17];
bool cmp(const string& a, const string& b) { return N[a] > N[b]; }
int rch[101];
bool canRch(int v) {
  if (rch[v] == -1) {
    rch[v] = 0;
    for (int i = 0; i < n; i++)
      if ((v - no[i]) >= 0 && canRch(v - no[i])) {
        rch[v] = 1;
        break;
      }
  }
  return (rch[v] == 1 ? true : false);
}
int main() {
  init_N();
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> e[i];
  sort(e, e + n, cmp);
  for (int i = 0; i < k; i++) cin >> e2[i];
  sort(e2, e2 + k, cmp);
  int sno = 0;
  for (int i = 0; i < n; i++) {
    no[i] = N[e[i]];
    sno += no[i];
  }
  int sno2 = 0;
  for (int i = 0; i < k; i++) {
    no2[i] = N[e2[i]];
    if (no2[i] > sno) {
      cout << "NO" << endl;
      return 0;
    }
    s[i] = 0;
    sno2 += no2[i];
  }
  if (sno != sno2) {
    cout << "NO" << endl;
    return 0;
  }
  memset(rch, -1, sizeof(rch));
  for (int i = 0; i < n; i++) rch[no[i]] = 1;
  for (int i = 0; i < k; i++)
    if (!canRch(no2[i])) {
      cout << "NO" << endl;
      return 0;
    }
  found = false;
  solve(0);
  if (found) {
    for (int i = 0; i < n; i++) r[b[i]].push_back(e[i]);
    cout << "YES" << endl;
    for (int i = 0; i < k; i++) {
      cout << r[i][0];
      for (unsigned int j = 1; j < r[i].size(); j++) cout << "+" << r[i][j];
      cout << "->" << e2[i] << endl;
    }
  } else
    cout << "NO" << endl;
  return 0;
}
