#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
map<int, string> m2;
int arr[5];
int main() {
  m["S"] = 0;
  m["M"] = 1;
  m["L"] = 2;
  m["XL"] = 3;
  m["XXL"] = 4;
  m2[0] = "S";
  m2[1] = "M";
  m2[2] = "L";
  m2[3] = "XL";
  m2[4] = "XXL";
  for (int n = 0; n < 5; n++) {
    scanf("%d", &arr[n]);
  }
  int N;
  scanf("%d", &N);
  for (int n = 0; n < N; n++) {
    string str;
    cin >> str;
    int pos = m[str];
    for (int n = 0; n < 5; n++) {
      if (pos + n < 5 && arr[pos + n] > 0) {
        arr[pos + n]--;
        cout << m2[pos + n] << endl;
        break;
      } else if (pos - n >= 0 && arr[pos - n] > 0) {
        arr[pos - n]--;
        cout << m2[pos - n] << endl;
        break;
      }
    }
  }
}
