#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string second;
    cin >> second;
    int m;
    cin >> m;
    vector<int> b(m);
    for (int I = 0; I < m; I++) {
      cin >> b[I];
    }
    map<char, int> occr;
    for (char c : second) {
      occr[c]++;
    }
    map<int, char> posChar;
    while (true) {
      int cont = 0;
      for (int I = 0; I < m; I++) {
        if (b[I] == 0) {
          cont++;
        }
      }
      if (cont == 0) {
        break;
      }
      auto it = occr.end();
      it--;
      char c = ' ';
      while (true) {
        if (it->second >= cont) {
          c = it->first;
          occr.erase(it);
          break;
        }
        auto temp = it;
        if (it != occr.begin()) {
          it--;
        }
        occr.erase(temp);
        if (temp == occr.begin()) {
          break;
        }
      }
      if (c == ' ') {
        break;
      }
      vector<int> tempB = b;
      for (int I = 0; I < m; I++) {
        if (tempB[I] == 0) {
          posChar[I] = c;
          int x = 1;
          for (int J = I - 1; J >= 0; J--) {
            if (tempB[J] > 0) {
              b[J] -= x;
            }
            x++;
          }
          x = 1;
          for (int J = I + 1; J < m; J++) {
            if (tempB[J] > 0) {
              b[J] -= x;
            }
            x++;
          }
          b[I] = -1;
        }
      }
    }
    for (pair<int, char> p : posChar) {
      cout << p.second;
    }
    cout << '\n';
  }
  return 0;
}
