#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793;
const int mod = 1e9 + 7;
int CASE = 1;
const int mxn = 1e3;
const long long infll = 1e18;
const int infi = 1e9;
bool prime(long long n) {
  if (n <= 1) return false;
  if (n == 2 or n == 3) return true;
  if (n % 2 == 0 or n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i += 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long __gcd(long long a, long long b) { return !b ? a : __gcd(b, a % b); }
long long power(long long a, long long b, long long MOD) {
  long long x = a, res = 1, p = b;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p >>= 1;
    x %= MOD, res %= MOD;
  }
  return res;
}
void solve() {
  vector<string> v = {"S", "M", "L", "XL", "XXL"};
  map<string, int> mp;
  for (long long i = 0; i < 5; i++) {
    int x;
    cin >> x;
    mp[v[i]] = x;
  }
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    if (mp[s])
      cout << s << '\n', mp[s]--;
    else {
      int index = find(v.begin(), v.end(), s) - v.begin();
      int i = 1;
      while (true) {
        if (index + i < 5 && mp[v[index + i]]) {
          cout << v[index + i] << '\n', mp[v[index + i]]--;
          break;
        }
        if (index - i >= 0 && mp[v[index - i]]) {
          cout << v[index - i] << '\n', mp[v[index - i]]--;
          break;
        }
        i++;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
