#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
const int MAX = 1000;
const int inf = 999999999;
const int p1 = 104393321, p2 = 104393329;
int a[MAX], ind;
map<string, int> d;
map<int, string> s;
int main() {
  ios::sync_with_stdio(0);
  d["S"] = 0;
  d["M"] = 1;
  d["L"] = 2;
  d["XL"] = 3;
  d["XXL"] = 4;
  for (__typeof((d).begin()) i = (d).begin(); i != (d).end(); ++i)
    s[(*(i)).second] = (*(i)).first;
  for (int i = (0); i < int(5); ++i) {
    cin >> a[i];
  }
  int n;
  cin >> n;
  for (int i = (0); i < int(n); ++i) {
    string x;
    cin >> x;
    ind = d[x];
    if (a[ind] > 0) {
      cout << s[ind] << endl;
      a[ind]--;
    } else {
      int r = ind, l = ind;
      while (r < 5) {
        if (a[r] > 0)
          break;
        else
          r++;
      }
      while (l >= 0) {
        if (a[l] > 0)
          break;
        else
          l--;
      }
      if (l < 0) {
        cout << s[r] << endl;
        a[r]--;
      } else if (r >= 5) {
        cout << s[l] << endl;
        a[l]--;
      } else {
        if (r - ind <= ind - l) {
          cout << s[r] << endl;
          a[r]--;
        } else {
          cout << s[l] << endl;
          a[l]--;
        }
      }
    }
  }
  return 0;
}
