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