#include <bits/stdc++.h>
using namespace std;
int b[500];
int cnt[27];
char ans[500];
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(cnt, 0, sizeof(cnt));
    memset(ans, 0, sizeof(ans));
    string str;
    cin >> str;
    for (int i = 0; i < str.length(); i++) {
      cnt[str[i] - 'a']++;
    }
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    int hello = 26;
    bool fxck = true;
    while (fxck) {
      fxck = false;
      queue<int> position;
      for (int i = 0; i < n; i++) {
        if (b[i] == 0 && ans[i] == 0) {
          position.push(i);
          fxck = true;
        }
      }
      while (cnt[hello] < position.size()) hello--;
      while (!position.empty()) {
        int top = position.front();
        position.pop();
        ans[top] = 'a' + hello;
        for (int i = 0; i < n; i++) {
          if (b[i] != 0) b[i] -= abs(i - top);
        }
      }
      hello--;
    }
    for (int i = 0; i < n; i++) {
      cout << ans[i];
    }
    cout << endl;
  }
}
