#include <bits/stdc++.h>
using namespace std;
long double pi = 3.1415926536;
bool comp(int a, int b) { return (a < b); }
int main() {
  vector<int> s(5);
  for (int i = 0; i < 5; ++i) cin >> s[i];
  int n;
  cin >> n;
  vector<int> k(n);
  string t;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    if (t[0] == 'S')
      k[i] = 0;
    else if (t[0] == 'M')
      k[i] = 1;
    else if (t[0] == 'L')
      k[i] = 2;
    else if (t[1] == 'L')
      k[i] = 3;
    else
      k[i] = 4;
  }
  int l, r, ind;
  vector<int> res;
  for (int i = 0; i < n; ++i) {
    if (s[k[i]] > 0) {
      s[k[i]]--;
      res.push_back(k[i]);
    } else {
      l = r = k[i];
      while (l > 0 && s[l] == 0) l--;
      while (r < 4 && s[r] == 0) r++;
      if ((s[r] == 0 || k[i] - l < r - k[i]) && s[l] > 0)
        ind = l;
      else if ((s[l] == 0 || k[i] - l >= r - k[i]) && s[r] > 0)
        ind = r;
      s[ind]--;
      res.push_back(ind);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (res[i] == 0)
      cout << "S";
    else if (res[i] == 1)
      cout << "M";
    else if (res[i] == 2)
      cout << "L";
    else if (res[i] == 3)
      cout << "XL";
    else
      cout << "XXL";
    cout << '\n';
  }
}
