#include <bits/stdc++.h>
using namespace std;
map<string, int> sz;
map<int, string> out;
int main() {
  ios_base::sync_with_stdio(0);
  int n[5];
  cin >> n[0] >> n[1] >> n[2] >> n[3] >> n[4];
  int k;
  cin >> k;
  sz["S"] = 0;
  sz["M"] = 1;
  sz["L"] = 2;
  sz["XL"] = 3;
  sz["XXL"] = 4;
  out[0] = "S";
  out[1] = "M";
  out[2] = "L";
  out[3] = "XL";
  out[4] = "XXL";
  for (int i = 0; i < k; i++) {
    string s;
    cin >> s;
    int c = sz[s];
    int x = 322;
    int y = 322;
    for (int j = c; j < 5; j++)
      if (n[j]) {
        x = j - c;
        break;
      }
    for (int j = c; j >= 0; j--)
      if (n[j]) {
        y = j - c;
        break;
      }
    int b = 0;
    if (x <= abs(y))
      b = x;
    else
      b = y;
    n[b + c]--;
    cout << out[b + c] << endl;
  }
  return 0;
}
