#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T x, T y) {
  while (T t = x % y) x = y, y = t;
  return y;
}
const double eps = 1e-10;
const double PI = acos(-1.);
const int INF = 1000000000;
const int MOD = 1000000007;
const double E = 2.7182818284590452353602874713527;
bool isdig(char x) { return x >= '0' && x <= '9'; }
bool isup(char x) { return x >= 'A' && x <= 'Z'; }
bool islow(char x) { return x >= 'a' && x <= 'z'; }
bool islet(char x) { return isup(x) || islow(x); }
int num[5];
int N;
map<string, int> mp;
void get_data() {
  mp.clear();
  mp["S"] = 0;
  mp["M"] = 1;
  mp["L"] = 2;
  mp["XL"] = 3;
  mp["XXL"] = 4;
  for (int i = 0; i < 5; i++) cin >> num[i];
  cin >> N;
}
bool ok(int x) {
  if (x < 0 || x > 4) return 0;
  return num[x];
}
string s[5];
void run() {
  s[0] = "S";
  s[1] = "M";
  s[2] = "L";
  s[3] = "XL";
  s[4] = "XXL";
  while (N--) {
    string a;
    cin >> a;
    int t = mp[a];
    for (int i = 0; i < 5; i++) {
      if (ok(i + t)) {
        cout << s[i + t] << endl;
        num[i + t]--;
        break;
      }
      if (ok(t - i)) {
        cout << s[t - i] << endl;
        num[t - i]--;
        break;
      }
    }
  }
}
int main(int argc, char *argv[]) {
  {
    get_data();
    run();
  }
  return EXIT_SUCCESS;
}
