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