#include <bits/stdc++.h>
using namespace std;
int main() {
  int x[5], i, j, k, r, dr, cr;
  string s[5] = {"S", "M", "L", "XL", "XXL"};
  string tmp;
  for (i = 0; i < 5; i++) cin >> x[i];
  cin >> k;
  for (i = 0; i < k; ++i) {
    cin >> tmp;
    for (j = 0; j < 5; ++j)
      if (s[j] == tmp) {
        break;
      }
    for (r = 0; r <= 4; r++)
      for (dr = 1; dr >= -1; dr = dr - 2) {
        cr = j + r * dr;
        if (cr >= 0 && cr < 5 && x[cr] > 0) {
          x[cr]--;
          cout << s[cr] << endl;
          goto lbl;
        }
      }
  lbl:
    i = i;
  }
  return 0;
}
