#include <bits/stdc++.h>
using namespace std;
void solve() {
  int a[5], i;
  for (int i = 0; i < 5; ++i) {
    cin >> a[i];
  }
  int k;
  cin >> k;
  string s;
  int p;
  while (k--) {
    cin >> s;
    if (s == "S")
      p = 0;
    else if (s == "M")
      p = 1;
    else if (s == "L")
      p = 2;
    else if (s == "XL")
      p = 3;
    else if (s == "XXL")
      p = 4;
    int j;
    if (a[p] > 0) {
      j = p;
      a[p] = a[p] - 1;
    } else {
      int b = p;
      p = b + 1, i = b - 1;
      while (p < 5 || i >= 0) {
        if (a[p] > 0 && p < 5) {
          a[p] = a[p] - 1;
          j = p;
          break;
        } else if (a[i] > 0 && i >= 0) {
          a[i] = a[i] - 1;
          j = i;
          break;
        }
        p++;
        i--;
      }
    }
    if (j == 0)
      cout << "S" << endl;
    else if (j == 1)
      cout << "M" << endl;
    else if (j == 2)
      cout << "L" << endl;
    else if (j == 3)
      cout << "XL" << endl;
    else if (j == 4)
      cout << "XXL" << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  solve();
}
