#include <bits/stdc++.h>
using namespace std;
char current[80];
char names[5][5] = {"S", "M", "L", "XL", "XXL"};
int texttoint() {
  if (strcmp(current, "S") == 0) return 0;
  if (strcmp(current, "M") == 0) return 1;
  if (strcmp(current, "L") == 0) return 2;
  if (strcmp(current, "XL") == 0) return 3;
  if (strcmp(current, "XXL") == 0) return 4;
  return -1;
}
int main() {
  int N[5];
  for (int i = 0; i < 5; i++) scanf("%d", &N[i]);
  int K;
  scanf("%d", &K);
  for (int i = 0; i < K; i++) {
    scanf("%s", current);
    int a = texttoint();
    for (int j = 0; j < 5; j++) {
      if (a + j < 5 && N[a + j] > 0) {
        N[a + j]--;
        printf("%s\n", names[a + j]);
        break;
      } else if (a - j >= 0 && N[a - j] > 0) {
        N[a - j]--;
        printf("%s\n", names[a - j]);
        break;
      }
    }
  }
  return 0;
}
