#include <iostream>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct Dinic {
struct Edge {
int to, rev;
ll c, oc;
ll flow() { return max(oc - c, 0LL); } // if you need flows
};
vi lvl, ptr, q;
vector<vector<Edge>> adj;
Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {}
void addEdge(int a, int b, ll c, ll rcap = 0) {
adj[a].push_back({b, sz(adj[b]), c, c});
adj[b].push_back({a, sz(adj[a]) - 1, rcap, rcap});
}
ll dfs(int v, int t, ll f) {
if (v == t || !f)
return f;
for (int &i = ptr[v]; i < sz(adj[v]); i++) {
Edge &e = adj[v][i];
if (lvl[e.to] == lvl[v] + 1)
if (ll p = dfs(e.to, t, min(f, e.c))) {
e.c -= p, adj[e.to][e.rev].c += p;
return p;
}
}
return 0;
}
ll calc(int s, int t) {
ll flow = 0;
q[0] = s;
rep(L, 0, 31) do { // 'int L=30' maybe faster for random data
lvl = ptr = vi(sz(q));
int qi = 0, qe = lvl[s] = 1;
while (qi < qe && !lvl[t]) {
int v = q[qi++];
for (Edge e : adj[v])
if (!lvl[e.to] && e.c >> (30 - L))
q[qe++] = e.to, lvl[e.to] = lvl[v] + 1;
}
while (ll p = dfs(s, t, LLONG_MAX))
flow += p;
}
while (lvl[t])
;
return flow;
}
bool leftOfMinCut(int a) { return lvl[a] != 0; }
};
void solve() {
int n, m;
cin >> n >> m;
vector<ll> limits(n + 1);
ll su = 0;
for (int i = 1; i <= n; i++) {
cin >> limits[i];
su += limits[i];
}
Dinic d(n + m + 2);
for (int i = 1; i <= n; i++) {
d.addEdge(i, n + m + 1, limits[i]);
}
vector<pair<int, int>> edgelookup(m + 1);
for (int i = 1; i <= m; i++) {
d.addEdge(0, n + i, 1);
int u, v;
cin >> u >> v;
edgelookup[i].first = d.adj[n + i].size();
d.addEdge(n + i, u, 1);
edgelookup[i].second = d.adj[n + i].size();
d.addEdge(n + i, v, 1);
}
d.calc(0, n + m + 1);
ll ans = 0;
vector<int> sans(m);
for (int i = 1; i <= m; i++) {
Dinic::Edge utv = d.adj[n + i][edgelookup[i].second];
Dinic::Edge vtu = d.adj[n + i][edgelookup[i].first];
if (utv.flow() == 1) {
sans[i - 1] = 0;
} else if (vtu.flow() == 1) {
sans[i - 1] = 1;
} else {
sans[i - 1] = 1;
ans++;
}
}
cout << ans << endl;
for (int x : sans) {
cout << x;
}
cout << endl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int t;
cin >> t;
while (t--)
solve();
}