#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-8;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 18;
int n, k, va[MAXN], vb[MAXN], vs[1 << MAXN];
int nxt[1 << MAXN], prv[1 << MAXN];
string a[MAXN], b[MAXN];
vector<int> g[MAXN];
map<string, int> m;
bool d[1 << MAXN];
void init() {
  m["H"] = 1;
  m["He"] = 2;
  m["Li"] = 3;
  m["Be"] = 4;
  m["B"] = 5;
  m["C"] = 6;
  m["N"] = 7;
  m["O"] = 8;
  m["F"] = 9;
  m["Ne"] = 10;
  m["Na"] = 11;
  m["Mg"] = 12;
  m["Al"] = 13;
  m["Si"] = 14;
  m["P"] = 15;
  m["S"] = 16;
  m["Cl"] = 17;
  m["Ar"] = 18;
  m["K"] = 19;
  m["Ca"] = 20;
  m["Sc"] = 21;
  m["Ti"] = 22;
  m["V"] = 23;
  m["Cr"] = 24;
  m["Mn"] = 25;
  m["Fe"] = 26;
  m["Co"] = 27;
  m["Ni"] = 28;
  m["Cu"] = 29;
  m["Zn"] = 30;
  m["Ga"] = 31;
  m["Ge"] = 32;
  m["As"] = 33;
  m["Se"] = 34;
  m["Br"] = 35;
  m["Kr"] = 36;
  m["Rb"] = 37;
  m["Sr"] = 38;
  m["Y"] = 39;
  m["Zr"] = 40;
  m["Nb"] = 41;
  m["Mo"] = 42;
  m["Tc"] = 43;
  m["Ru"] = 44;
  m["Rh"] = 45;
  m["Pd"] = 46;
  m["Ag"] = 47;
  m["Cd"] = 48;
  m["In"] = 49;
  m["Sn"] = 50;
  m["Sb"] = 51;
  m["Te"] = 52;
  m["I"] = 53;
  m["Xe"] = 54;
  m["Cs"] = 55;
  m["Ba"] = 56;
  m["La"] = 57;
  m["Ce"] = 58;
  m["Pr"] = 59;
  m["Nd"] = 60;
  m["Pm"] = 61;
  m["Sm"] = 62;
  m["Eu"] = 63;
  m["Gd"] = 64;
  m["Tb"] = 65;
  m["Dy"] = 66;
  m["Ho"] = 67;
  m["Er"] = 68;
  m["Tm"] = 69;
  m["Yb"] = 70;
  m["Lu"] = 71;
  m["Hf"] = 72;
  m["Ta"] = 73;
  m["W"] = 74;
  m["Re"] = 75;
  m["Os"] = 76;
  m["Ir"] = 77;
  m["Pt"] = 78;
  m["Au"] = 79;
  m["Hg"] = 80;
  m["Tl"] = 81;
  m["Pb"] = 82;
  m["Bi"] = 83;
  m["Po"] = 84;
  m["At"] = 85;
  m["Rn"] = 86;
  m["Fr"] = 87;
  m["Ra"] = 88;
  m["Ac"] = 89;
  m["Th"] = 90;
  m["Pa"] = 91;
  m["U"] = 92;
  m["Np"] = 93;
  m["Pu"] = 94;
  m["Am"] = 95;
  m["Cm"] = 96;
  m["Bk"] = 97;
  m["Cf"] = 98;
  m["Es"] = 99;
  m["Fm"] = 100;
  m["Md"] = 101;
  m["No"] = 102;
  m["Lr"] = 103;
  m["Rf"] = 104;
  m["Db"] = 105;
}
void print(vector<int> t, string el) {
  for (int i = 0; i < (int)(t.size()); i++) {
    if (i != 0) cout << "+";
    cout << a[t[i]];
  }
  cout << "->" << el << endl;
}
vector<int> toVector(int mask) {
  vector<int> a;
  for (int i = 0; i < (int)(n); i++)
    if ((mask & (1 << i)) != 0) a.push_back(i);
  return a;
}
void solve(int mask, int v) {
  if (mask == 0) return;
  solve(mask ^ prv[mask], v - 1);
  print(toVector(prv[mask]), b[v]);
}
int main() {
  init();
  cin >> n >> k;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    va[i] = m[a[i]];
  }
  memset(nxt, 255, sizeof nxt);
  nxt[0] = 0;
  for (int mask = 0; mask < (int)(1 << n); mask++)
    for (int i = 0; i < (int)(n); i++)
      if ((mask & (1 << i)) != 0) vs[mask] += va[i];
  int sum = 0;
  for (int i = 0; i < (int)(k); i++) {
    cin >> b[i];
    vb[i] = m[b[i]];
    sum += vb[i];
    for (int mask = 0; mask < (int)(1 << n); mask++) {
      if (vs[mask] == vb[i]) g[i].push_back(mask);
      if (vs[mask] == sum) nxt[mask] = i + 1;
    }
  }
  d[0] = true;
  for (int mask = 0; mask < (int)(1 << n); mask++) {
    if (!d[mask] || nxt[mask] == -1) continue;
    int id = nxt[mask];
    for (int i = 0; i < (int)(g[id].size()); i++) {
      int nm = g[id][i];
      if ((mask & nm) == 0) {
        prv[mask ^ nm] = nm;
        d[mask ^ nm] = true;
      }
    }
  }
  int M = (1 << n) - 1;
  if (!d[M]) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  solve(M, k - 1);
  return 0;
}
