#include <bits/stdc++.h>
using namespace std;
int num[5];
int choose(int x) {
  int ret = 0;
  for (int i = 0; i < 5; ++i) {
    for (int k = 1; k >= -1; k -= 2) {
      int p = x + k * i;
      if (p >= 0 && p < 5)
        if (num[p] > 0) {
          num[p]--;
          return p;
        }
    }
  }
  return -1;
}
string d[5] = {"S", "M", "L", "XL", "XXL"};
int main() {
  map<string, int> m;
  m["S"] = 0;
  m["M"] = 1;
  m["L"] = 2;
  m["XL"] = 3;
  m["XXL"] = 4;
  for (int i = 0; i < 5; ++i) cin >> num[i];
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int ind = m[s];
    cout << d[choose(ind)] << endl;
  }
  return 0;
}
