#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-10;
template <typename T, typename S>
vector<T>& operator<<(vector<T>& a, S b) {
  a.push_back(b);
  return a;
}
template <typename T>
void operator>>(vector<T>& a, int b) {
  while (b--)
    if (!a.empty()) a.pop_back();
}
bool isprime(int n) {
  if (n < 2) return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
long long b_pow(long long x, long long n) {
  return n ? n == 1 ? x : b_pow(x, n >> 1) * b_pow(x, (n >> 1) + (n & 1)) : 1;
}
string itos(int n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
string table[119] = {
    "-",  "H",  "He", "Li", "Be", "B",   "C",   "N",   "O",   "F",   "Ne", "Na",
    "Mg", "Al", "Si", "P",  "S",  "Cl",  "Ar",  "K",   "Ca",  "Sc",  "Ti", "V",
    "Cr", "Mn", "Fe", "Co", "Ni", "Cu",  "Zn",  "Ga",  "Ge",  "As",  "Se", "Br",
    "Kr", "Rb", "Sr", "Y",  "Zr", "Nb",  "Mo",  "Tc",  "Ru",  "Rh",  "Pd", "Ag",
    "Cd", "In", "Sn", "Sb", "Te", "I",   "Xe",  "Cs",  "Ba",  "La",  "Ce", "Pr",
    "Nd", "Pm", "Sm", "Eu", "Gd", "Tb",  "Dy",  "Ho",  "Er",  "Tm",  "Yb", "Lu",
    "Hf", "Ta", "W",  "Re", "Os", "Ir",  "Pt",  "Au",  "Hg",  "Tl",  "Pb", "Bi",
    "Po", "At", "Rn", "Fr", "Ra", "Ac",  "Th",  "Pa",  "U",   "Np",  "Pu", "Am",
    "Cm", "Bk", "Cf", "Es", "Fm", "Md",  "No",  "Lr",  "Rf",  "Db",  "Sg", "Bh",
    "Hs", "Mt", "Ds", "Rg", "Cn", "Uut", "Uuq", "Uup", "Uuh", "Uus", "Uuo"};
vector<int> item, goal, able[17];
int n, m;
void output(int bit, int num) {
  vector<string> ans;
  for (int i = 0; i < n; i++)
    if (bit & (1 << i)) ans.push_back(table[item[i]]);
  for (int i = 0; i < ans.size(); i++) cout << (i ? "+" : "") << ans[i];
  cout << "->" << table[goal[num]] << endl;
}
vector<int> currentUsing;
bool done[1 << 17][17];
bool dfs(int pos, int bit) {
  if (pos == m) {
    cout << "YES" << endl;
    for (int i = 0; i < pos; i++) output(currentUsing[i], i);
    return true;
  }
  if (done[bit][pos])
    return false;
  else
    done[bit][pos] = 1;
  for (int i = 0; i < able[pos].size(); i++) {
    if (bit & able[pos][i]) continue;
    currentUsing.push_back(able[pos][i]);
    if (dfs(pos + 1, bit | able[pos][i])) return true;
    currentUsing.pop_back();
  }
  return false;
}
int main() {
  cin >> n >> m;
  string tmp;
  for (int i = 0; i < n; i++)
    cin >> tmp, item.push_back(find(table, table + 119, tmp) - table);
  for (int i = 0; i < m; i++)
    cin >> tmp, goal.push_back(find(table, table + 119, tmp) - table);
  for (int i = 0; i < m; i++) {
    for (int bit = 0; bit < (1 << n); bit++) {
      int sum = 0;
      for (int j = 0; j < n; j++)
        if (bit & (1 << j)) sum += item[j];
      if (sum == goal[i]) able[i].push_back(bit);
    }
  }
  if (!dfs(0, 0)) cout << "NO" << endl;
}
