#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int a, b, c, d, i, j, n, m, k;
int cnt[6];
map<string, int> q;
const int di[] = {0, 1, -1, 2, -2, 3, -3, 4, -4};
const char *name[] = {"S", "M", "L", "XL", "XXL"};
int main() {
  for (int _n((5) - 1), i(0); i <= _n; i++) scanf("%d", &cnt[i]);
  q["S"] = 0;
  q["M"] = 1;
  q["L"] = 2;
  q["XL"] = 3;
  q["XXL"] = 4;
  scanf("%d", &n);
  for (int _n((n)-1), i(0); i <= _n; i++) {
    string s;
    cin >> s;
    a = q[s];
    for (int _n((9) - 1), j(0); j <= _n; j++) {
      if (a + di[j] >= 0 && a + di[j] < 5 && cnt[a + di[j]]) {
        printf("%s\n", name[a + di[j]]);
        --cnt[a + di[j]];
        break;
      }
    }
  }
}
