#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int w[10];
string s[10] = {"", "S", "M", "L", "XL", "XXL"};
int main(void) {
  m["S"] = 1;
  m["M"] = 2;
  m["L"] = 3;
  m["XL"] = 4;
  m["XXL"] = 5;
  ios::sync_with_stdio(false);
  cin.tie(0);
  int p, T;
  for (int i = 1; i <= 5; i++) cin >> p, w[i] = p;
  cin >> T;
  while (T--) {
    string str;
    cin >> str;
    int x = m[str];
    for (int i = 0; i <= 4; i++) {
      if (x + i <= 5)
        if (w[x + i]) {
          w[x + i]--;
          cout << s[x + i] << '\n';
          break;
        }
      if (x - i >= 1)
        if (w[x - i]) {
          w[x - i]--;
          cout << s[x - i] << '\n';
          break;
        }
    }
  }
  return 0;
}
