#include <bits/stdc++.h>
const long j = 5;
long a[10];
long now, i, q, m;
char c, c2;
void solve() {
  long d, choice, left, right;
  for (d = 0; d <= 4; d++) {
    left = now - d;
    if (left < 0) left = 0;
    right = now + d;
    if (right > j) right = j + 1;
    if (a[right] != 0) {
      choice = right;
      break;
    } else if (a[left] != 0) {
      choice = left;
      break;
    }
  }
  switch (choice) {
    case 1: {
      printf("S");
      break;
    }
    case 2: {
      printf("M");
      break;
    }
    case 3: {
      printf("L");
      break;
    }
    case 4: {
      printf("XL");
      break;
    }
    case 5: {
      printf("XXL");
      break;
    }
  }
  a[choice]--;
  printf("\n");
}
int main() {
  for (i = 1; i <= 5; i++) scanf("%ld", &a[i]);
  a[0] = 0;
  a[6] = 0;
  scanf("%ld\n", &m);
  for (q = 1; q <= m; q++) {
    c = getchar();
    if (c == 'S')
      now = 1;
    else if (c == 'M')
      now = 2;
    else if (c == 'L')
      now = 3;
    else {
      c2 = getchar();
      if (c2 == 'L')
        now = 4;
      else
        now = 5;
    }
    solve();
    while (c != '\n') c = getchar();
  }
}
