#include <bits/stdc++.h>
using namespace std;
long long calcsum(long long i, vector<long long> v) {
  long long n = v.size();
  long long sum = 0;
  for (long long op = 0; op < n; ++op) {
    sum += abs(i - v[op]);
  }
  return sum;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long m;
    cin >> m;
    long long count = 0;
    long long* arr = new long long[m];
    char* arr1 = new char[m];
    for (long long i = 0; i < m; ++i) {
      cin >> arr[i];
      if (arr[i] == 0) {
        ++count;
      }
      arr1[i] = '?';
    }
    long long n = s.size();
    map<char, long long> m1;
    for (long long i = 0; i < n; ++i) {
      ++m1[s[i]];
    }
    map<char, long long>::iterator it = m1.end();
    --it;
    while (true) {
      if (it->second >= count) {
        break;
      }
      --it;
    }
    long long left = m;
    vector<long long> v;
    char cur = it->first;
    for (long long i = 0; i < m; ++i) {
      if (arr[i] == 0) {
        arr1[i] = cur;
        v.push_back(i);
        --left;
      }
    }
    while (left > 0) {
      --it;
      vector<long long> aux;
      for (long long i = 0; i < m; ++i) {
        if (arr1[i] == '?') {
          if (calcsum(i, v) == arr[i]) {
            aux.push_back(i);
          }
        }
      }
      long long last = aux.size();
      while (it->second < last) {
        --it;
      }
      for (long long i = 0; i < last; ++i) {
        v.push_back(aux[i]);
        arr1[aux[i]] = it->first;
        --left;
      }
    }
    for (long long i = 0; i < m; ++i) {
      cout << arr1[i];
    }
    cout << endl;
  }
}
