#include <bits/stdc++.h>
using namespace std;
int num[5];
int Abs(int a) { return a > 0 ? a : -a; }
string ff[] = {"S", "M", "L", "XL", "XXL"};
int main() {
  int n;
  map<string, int> f;
  int ns;
  for (int i = 0; i < 5; i++) cin >> num[i];
  f["S"] = 0;
  f["M"] = 1;
  f["L"] = 2;
  ;
  f["XL"] = 3;
  f["XXL"] = 4;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string cur;
    cin >> cur;
    int ii = f[cur];
    int best = 1000;
    int bj = 5;
    for (int j = 4; j >= 0; j--)
      if (num[j] > 0 && Abs(j - ii) < best) {
        best = Abs(j - ii);
        bj = j;
      }
    num[bj]--;
    cout << ff[bj] << endl;
  }
  return 0;
}
