#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
void fill_(S& buf, const T& x) {
  fill_n(reinterpret_cast<T*>(&buf), sizeof(buf) / sizeof(T), x);
}
template <typename T>
inline vector<T>& operator+=(vector<T>& ret, const T& x) {
  ret.push_back(x);
  return ret;
}
int N;
map<string, int> m;
int xs[5];
int main(int argc, char* argv[]) {
  char* sizes[] = {"S", "M", "L", "XL", "XXL"};
  for (int i = int(0), CNT_i = int(5); i < CNT_i; ++i) m[sizes[i]] = i;
  for (int i = int(0), CNT_i = int(5); i < CNT_i; ++i) cin >> xs[i];
  cin >> N;
  string s;
  for (int i = int(0), CNT_i = int(N); i < CNT_i; ++i) {
    cin >> s;
    int d = 0, sign = -1;
    int idx = m[s];
    for (int j = int(0), CNT_j = int(9); j < CNT_j; ++j) {
      idx += d * sign;
      if (0 <= idx && idx < 5 && xs[idx] > 0) {
        --xs[idx];
        cout << sizes[idx] << endl;
        break;
      }
      ++d;
      sign *= -1;
    }
  }
  return 0;
}
