#include <bits/stdc++.h>
using namespace std;
int main() {
  int c[100], w[2000], q[2000];
  int b[100];
  for (int i = 0; i <= 20; i++) {
    q[i] = 0;
    b[i] = 0;
    c[i] = 0;
  }
  for (int i = 5; i <= 9; i++) {
    cin >> c[i];
  }
  int n = 0;
  string a;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (a == "S") {
      b[1]++;
      q[i] = 5;
    }
    if (a == "M") {
      b[2]++;
      q[i] = 6;
    }
    if (a == "L") {
      b[3]++;
      q[i] = 7;
    }
    if (a == "XL") {
      b[4]++;
      q[i] = 8;
    }
    if (a == "XXL") {
      b[5]++;
      q[i] = 9;
    }
  }
  for (int i = 0; i <= 20; i++) w[i] = 0;
  for (int i = 1; i <= n; i++) {
    if (c[q[i]] != 0) {
      w[i] = 0;
      c[q[i]]--;
    } else {
      if (c[q[i] + 1] != 0) {
        w[i] = 1;
        c[q[i] + 1]--;
      } else {
        if (c[q[i] - 1] != 0) {
          w[i] = -1;
          c[q[i] - 1]--;
        } else {
          if (c[q[i] + 2] != 0) {
            w[i] = 2;
            c[q[i] + 2]--;
          } else {
            if (c[q[i] - 2] != 0) {
              w[i] = -2;
              c[q[i] - 2]--;
            } else {
              if (c[q[i] + 3] != 0) {
                w[i] = 3;
                c[q[i] + 3]--;
              } else {
                if (c[q[i] - 3] != 0) {
                  w[i] = -3;
                  c[q[i] - 3]--;
                } else {
                  if (c[q[i] + 4] != 0) {
                    w[i] = 4;
                    c[q[i] + 4]--;
                  } else {
                    if (c[q[i] - 4] != 0) {
                      w[i] = -4;
                      c[q[i] - 4]--;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    w[i] += q[i];
  }
  for (int i = 1; i <= n; i++) {
    if (w[i] == 5) cout << "S" << endl;
    if (w[i] == 6) cout << "M" << endl;
    if (w[i] == 7) cout << "L" << endl;
    if (w[i] == 8) cout << "XL" << endl;
    if (w[i] == 9) cout << "XXL" << endl;
  }
  return 0;
}
