#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> ans;
  int K = 0;
  map<string, int> s, d;
  string temp;
  d["S"] = 0;
  d["M"] = 1;
  d["L"] = 2;
  d["XL"] = 3;
  d["XXL"] = 4;
  s["S"] = 0;
  s["M"] = 0;
  s["L"] = 0;
  s["XL"] = 0;
  s["XXL"] = 0;
  cin >> s["S"];
  cin >> s["M"];
  cin >> s["L"];
  cin >> s["XL"];
  cin >> s["XXL"];
  cin >> K;
  for (int i = 0; i < K; i++) {
    cin >> temp;
    int dist = 10;
    int prior = -1;
    string res;
    for (map<string, int>::iterator itr = s.begin(); itr != s.end(); itr++) {
      if (itr->second != 0) {
        if (dist > abs(d[itr->first] - d[temp])) {
          res = itr->first;
          dist = abs(d[itr->first] - d[temp]);
          prior = d[itr->first];
        } else if ((dist == abs(d[itr->first] - d[temp])) &&
                   (prior < d[itr->first])) {
          res = itr->first;
          prior = d[itr->first];
        }
      }
    }
    ans.push_back(res);
    s[res]--;
  }
  for (vector<string>::iterator itr = ans.begin(); itr != ans.end(); itr++)
    cout << *itr << "\n";
  return 0;
}
