#include <bits/stdc++.h>
using namespace std;
int main() {
  string c, s[5] = {"S", "M", "L", "XL", "XXL"};
  int a[5], k;
  for (int i = 0; i < 5; i++) cin >> a[i];
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> c;
    int p;
    for (int j = 0; j < 5; j++)
      if (s[j] == c) p = j;
    int st = 1;
    while (a[p] == 0) {
      if (a[p + st] > 0 && p + st < 5)
        p += st;
      else if (a[p - st] > 0 && p - st >= 0)
        p -= st;
      st++;
    }
    cout << s[p] << endl;
    a[p]--;
  }
  return 0;
}
