#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return (b == 0) ? abs(a) : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
inline T mod(T a, T b) {
  return (a % b + b) % b;
}
template <typename T>
inline T sqr(T x) {
  return x * x;
}
template <typename T>
inline string tostring(const T& x) {
  ostringstream os;
  os << x;
  return os.str();
}
inline int toint(const string& s) {
  istringstream is(s);
  int x;
  is >> x;
  return x;
}
inline double todouble(const string& s) {
  istringstream is(s);
  double x;
  is >> x;
  return x;
}
inline string tobinary(int a) {
  string s;
  while (a != 0) {
    s = (char)(a % 2 + '0') + s;
    a >>= 1;
  }
  return s;
}
inline int isvowel(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return 1;
  return 0;
}
inline int isprime(int a) {
  for (int i = 2; i * i <= a; i++)
    if (!(a % i)) return 0;
  return 1;
}
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
void debugarr(int* arr, int n) {
  cout << "[";
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << "]" << endl;
}
long long powmod(long long b, long long p, long long m) {
  long long r = 1;
  for (int i = (1 << 30); i; i >>= 1) {
    r *= r;
    r %= m;
    if (p & i) {
      r *= b;
      r %= m;
    }
  }
  return (long long)r;
}
int main() {
  int pref[10][5];
  pref[1][1] = 1;
  pref[1][2] = 2;
  pref[1][3] = 3;
  pref[1][4] = 4;
  pref[1][5] = 5;
  pref[2][1] = 2;
  pref[2][2] = 3;
  pref[2][3] = 1;
  pref[2][4] = 4;
  pref[2][5] = 5;
  pref[3][1] = 3;
  pref[3][2] = 4;
  pref[3][3] = 2;
  pref[3][4] = 5;
  pref[3][5] = 1;
  pref[4][1] = 4;
  pref[4][2] = 5;
  pref[4][3] = 3;
  pref[4][4] = 2;
  pref[4][5] = 1;
  pref[5][1] = 5;
  pref[5][2] = 4;
  pref[5][3] = 3;
  pref[5][4] = 2;
  pref[5][5] = 1;
  int m[6];
  map<string, int> p;
  map<int, string> make_pair;
  make_pair[1] = "S";
  make_pair[2] = "M";
  make_pair[3] = "L";
  make_pair[4] = "XL";
  make_pair[5] = "XXL";
  m[1] = 0;
  m[2] = 0;
  m[3] = 0;
  m[4] = 0;
  m[5] = 0;
  p["S"] = 1;
  p["M"] = 2;
  p["L"] = 3;
  p["XL"] = 4;
  p["XXL"] = 5;
  int temp;
  for (int i = (1); i <= (5); i++) {
    cin >> temp;
    m[i] = temp;
  }
  int N;
  string str;
  scanf("%d", &N);
  for (int i = (0); i <= (N - 1); i++) {
    cin >> str;
    for (int j = 1; j <= 5; j++) {
      if (m[pref[p[str]][j]]) {
        m[pref[p[str]][j]]--;
        cout << make_pair[pref[p[str]][j]] << endl;
        break;
      }
    }
  }
  return 0;
}
