#include <bits/stdc++.h>
using namespace std;
struct pair_hash {
  template <class T1, class T2>
  std::size_t operator()(std::pair<T1, T2> const &pair) const {
    std::size_t h1 = std::hash<T1>()(pair.first);
    std::size_t h2 = std::hash<T2>()(pair.second);
    return h1 ^ h2;
  }
};
unsigned long long max(unsigned long long a[], unsigned long long b[]) {
  unsigned long long r(*a);
  unsigned long long *k = a;
  while (k != b) {
    r = (r > (*k)) ? r : (*k);
    k++;
  }
  return r;
}
unsigned long long min(unsigned long long a[], unsigned long long b[]) {
  unsigned long long r(*a);
  unsigned long long *k = a;
  while (k != b) {
    r = (r < (*k)) ? r : (*k);
    k++;
  }
  return r;
}
void sieve(bool prime[], int n) {
  memset(prime, true, sizeof(bool) * n);
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
template <typename T>
bool compair(pair<T, T> a, pair<T, T> b) {
  return a.second < b.second;
}
void solve() {
  int a[5];
  for (long long i(0); i < 5; i++) cin >> a[i];
  int n, k;
  cin >> n;
  for (long long i(0); i < n; i++) {
    string s;
    cin >> s;
    if (s.size() == 2) k = 3;
    if (s.size() == 3) k = 4;
    switch (s[0]) {
      case 'S':
        k = 0;
        break;
      case 'M':
        k = 1;
        break;
      case 'L':
        k = 2;
        break;
    }
    int p(-1);
    for (long long i(0); i < 5; i++) {
      if (a[k] != 0) {
        a[k]--;
        p = k;
        break;
      }
      if (k + i < 5 && a[k + i] != 0) {
        a[i + k]--;
        p = i + k;
        break;
      }
      if (k - i >= 0 && a[k - i] != 0) {
        a[k - i]--;
        p = k - i;
        break;
      }
    }
    switch (p) {
      case 0:
        cout << 'S';
        break;
      case 1:
        cout << 'M';
        break;
      case 2:
        cout << 'L';
        break;
      case 3:
        cout << "XL";
        break;
      case 4:
        cout << "XXL";
        break;
    }
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  { solve(); }
  return 0;
}
