#include <bits/stdc++.h>
using namespace std;
class Edge {
 public:
  int src, dest;
};
class Graph {
 public:
  int V, E;
  Edge *edge;
};
Graph *createGraph(int V, int E) {
  Graph *graph = new Graph();
  graph->V = V;
  graph->E = E;
  graph->edge = new Edge[graph->E * sizeof(Edge)];
  return graph;
}
int find(int parent[], int i) {
  if (parent[i] == -1) return i;
  return find(parent, parent[i]);
}
void Union(int parent[], int x, int y) {
  int xset = find(parent, x);
  int yset = find(parent, y);
  if (xset != yset) {
    parent[xset] = yset;
  }
}
int isCycle(Graph *graph) {
  int *parent = new int[graph->V * sizeof(int)];
  memset(parent, -1, sizeof(int) * graph->V);
  for (int i = 0; i < graph->E; ++i) {
    int x = find(parent, graph->edge[i].src);
    int y = find(parent, graph->edge[i].dest);
    if (x == y) return 1;
    Union(parent, x, y);
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T;
  cin >> T;
  for (int test = 0; test < T; test++) {
    int m;
    string s;
    cin >> s;
    cin >> m;
    int arr[m];
    for (int i = 0; i < m; i++) cin >> arr[i];
    vector<vector<int>> v;
    int size = m;
    while (size > 0) {
      int count = 0;
      vector<int> v1;
      for (int i = 0; i <= m - 1; i++) {
        if (arr[i] == 0) {
          count++;
          v1.push_back(i);
        }
      }
      v.push_back(v1);
      for (int i = 0; i <= m - 1; i++) {
        if (arr[i] == 0)
          arr[i] = -1;
        else if (arr[i] > 0) {
          for (int k = 0; k <= count - 1; k++) arr[i] -= abs(i - v1[k]);
        }
      }
      size -= count;
    }
    int f[26];
    memset(f, 0, sizeof(f));
    for (int i = 0; i <= s.length() - 1; i++) f[s[i] - 'a']++;
    int co = v.size();
    char a[co];
    int pos = 25;
    for (int i = 0; i <= co - 1; i++) {
      int fq = v[i].size();
      while (f[pos] < fq && pos >= 0) pos--;
      a[i] = (char)('a' + pos);
      pos--;
    }
    char ans[m];
    for (int i = 0; i <= co - 1; i++) {
      for (int j = 0; j <= v[i].size() - 1; j++) ans[v[i][j]] = a[i];
    }
    for (int i = 0; i <= m - 1; i++) cout << ans[i];
    cout << "\n";
  }
  return 0;
}
