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