#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  vector<int> arr(5);
  for (auto& v : arr) cin >> v;
  int n;
  cin >> n;
  while (n--) {
    string cmd;
    cin >> cmd;
    int index;
    if (cmd == "S") index = 0;
    if (cmd == "M") index = 1;
    if (cmd == "L") index = 2;
    if (cmd == "XL") index = 3;
    if (cmd == "XXL") index = 4;
    if (arr[index])
      --arr[index];
    else {
      vector<int> cur;
      int minn = (0x3f3f3f3f);
      for (int i = 0; i != 5; ++i)
        if (arr[i])
          if (abs(i - index) < minn) {
            cur.clear();
            minn = abs(i - index);
            cur.push_back(i);
          } else if (abs(i - index) == minn)
            cur.push_back(i);
      if (((int)cur.size()) == 2) sort(cur.begin(), cur.end(), greater<int>());
      --arr[cur[0]];
      index = cur[0];
    }
    switch (index) {
      case 0:
        cout << "S" << '\n';
        break;
      case 1:
        cout << "M" << '\n';
        break;
      case 2:
        cout << "L" << '\n';
        break;
      case 3:
        cout << "XL" << '\n';
        break;
      case 4:
        cout << "XXL" << '\n';
        break;
    }
  }
  return 0;
}
