#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> v;
  v.push_back("S");
  v.push_back("M");
  v.push_back("L");
  v.push_back("XL");
  v.push_back("XXL");
  map<string, int> m;
  int arr[5];
  for (int i = 0; i < 5; i++) {
    cin >> arr[i];
  }
  m["S"] = arr[0];
  m["M"] = arr[1];
  m["L"] = arr[2];
  m["XL"] = arr[3];
  m["XXL"] = arr[4];
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    string a;
    cin >> a;
    if (m[a] > 0) {
      cout << a << endl;
      m[a]--;
    } else {
      int idx = find(v.begin(), v.end(), a) - v.begin();
      int l = idx - 1;
      int r = idx + 1;
      int cnt = 0;
      while (l >= 0 || r < 5) {
        if (r < 5) {
          if (m[v[r]] > 0) {
            cout << v[r] << endl;
            m[v[r]]--;
            break;
          } else
            r++;
        }
        if (l >= 0) {
          if (m[v[l]] > 0) {
            cout << v[l] << endl;
            m[v[l]]--;
            break;
          } else
            l--;
        }
      }
    }
  }
  return 0;
}
