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