#include <bits/stdc++.h>
using namespace std;
int hv[5];
map<string, int> dys;
string dyi[5] = {"S", "M", "L", "XL", "XXL"};
int order[5][5] = {{0, 1, 2, 3, 4},
                   {1, 2, 0, 3, 4},
                   {2, 3, 1, 4, 0},
                   {3, 4, 2, 1, 0},
                   {4, 3, 2, 1, 0}};
int k;
string sk;
void init() {
  dys["S"] = 0;
  dys["M"] = 1;
  dys["L"] = 2;
  dys["XL"] = 3;
  dys["XXL"] = 4;
}
int main() {
  init();
  for (int i = 0; i < 5; i++) scanf("%d", hv + i);
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    cin >> sk;
    int dyk = dys[sk];
    for (int j = 0; j < 5; j++)
      if (hv[order[dyk][j]]) {
        hv[order[dyk][j]]--;
        cout << dyi[order[dyk][j]] << endl;
        break;
      }
  }
  return 0;
}
