#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  cin >> test;
  while (test--) {
    char array[51];
    int fin[51];
    int length;
    cin >> array >> length;
    vector<char> ans(length, '.');
    vector<int> fr(26, 0);
    for (int i = 0; i < strlen(array); i++) {
      fr[array[i] - 'a']++;
    }
    for (int i = 0; i < length; i++) {
      cin >> fin[i];
    }
    char c = 'z';
    while (true) {
      vector<int> zeroes;
      for (int i = 0; i < length; i++) {
        if (fin[i] == 0) zeroes.push_back(i), fin[i] = -1;
      }
      if (zeroes.empty()) break;
      while (c >= 'a' && fr[c - 'a'] < zeroes.size()) c--;
      for (int pos : zeroes) ans[pos] = c;
      for (int i = 0; i < length; i++) {
        if (ans[i] == '.' || ans[i] < c) {
          for (int pos : zeroes) {
            fin[i] -= abs(pos - i);
          }
        }
      }
      c--;
    }
    for (auto m : ans) cout << m;
    cout << endl;
  }
}
