#include <bits/stdc++.h>
namespace std {
long long abs(long long x) { return x < 0 ? -x : x; }
}  // namespace std
using namespace std;
void dprintf(char* format, ...) {
  fprintf(stderr, "DEBUG: ");
  va_list argp;
  va_start(argp, format);
  vfprintf(stderr, format, argp);
  va_end(argp);
  fprintf(stderr, "\n");
}
struct Exception {
  const char* message;
  const int line;
  Exception(const char* m, int l) : message(m), line(l) {}
};
static char stringReader[2097152];
static inline bool ReadLine() {
  char* ptr = fgets(stringReader, sizeof(stringReader), stdin);
  if (ptr == 0) return false;
  int N = strlen(stringReader);
  if (stringReader[N - 1] == '\n') stringReader[N - 1] = 0;
  return true;
}
const long long ooLL = 0x3f3f3f3f3f3f3f3fLL;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
int main() {
  try {
    int sizes[5];
    for (int i = 0; i < 5; ++i) scanf("%d", sizes + i);
    int N;
    scanf("%d", &N);
    map<string, int> s;
    s["S"] = 0;
    s["M"] = 1;
    s["L"] = 2;
    s["XL"] = 3;
    s["XXL"] = 4;
    char* names[] = {"S", "M", "L", "XL", "XXL"};
    for (int i = 0; i < N; ++i) {
      char size[8];
      scanf("%s", size);
      bool done = false;
      for (int d = 0; !done; ++d) {
        for (int j = 1; j >= -1; j -= 2) {
          int x = s[size] + d * j;
          if (x >= 0 && x < 5 && sizes[x]) {
            done = true;
            printf("%s\n", names[x]);
            --sizes[x];
            break;
          }
        }
      }
    }
    return 0;
  } catch (const Exception& exception) {
    fprintf(stderr, "******************************\n");
    fprintf(stderr, "ERROR.%d: %s\n", exception.line, exception.message);
    fprintf(stderr, "******************************\n");
    throw exception;
  }
}
