// Arup Guha
// 1/19/2016
// Solution to Proposed 2016 Mercer Contest Problem: Intergalactic Soccer

import java.util.*;

public class prob10 {

	// Multiplicative factor to convert decimals to integers and vice versa, since
	// all input doubles have no more that 4 digits past the decimal.
	final public static double FACTOR = 10000.0;

	final public static int NOPATH = -1;

	public static int n;
	public static ArrayList[] graph;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=0; loop<numCases; loop++) {

			// Form data structure to hold graph.
			n = stdin.nextInt();
			graph = new ArrayList[n+1];
			for (int i=0; i<n+1; i++)
				graph[i] = new ArrayList<edge>();

			// Store probabilities for shots on goal.
			for (int i=0; i<n; i++) {
				int dist = convert(stdin.nextDouble());
				graph[i].add(new edge(n, dist));
			}

			// Add in each pass probability.
			int numEdges = stdin.nextInt();
			for (int i=0; i<numEdges; i++) {
				int v1 = stdin.nextInt()-1;
				int v2 = stdin.nextInt()-1;
				int dist = convert(stdin.nextDouble());
				graph[v1].add(new edge(v2, dist));
			}

			// Solve and output the result.
			System.out.printf("%.3f\n", solve());
		}
	}

	// Returns an integer version of x. Specifically -10000*x, assuming x was represented to
	// no more than 4 decimal places.
	public static int convert(double x) {
		return (int)(-x*FACTOR + .01);
	}

	// Solves the problem at hand, using Dijkstra's algorithm.
	public static double solve() {

		// Get the minimum distance from player 1 to goal of the adjusted weights.
		int mindist = dijkstras(0, n);

		// This is the corresponding desired probability, accounting for special code for
		// impossible shots on goal.
		return mindist < 0 ? 0 : Math.pow(2, -mindist/FACTOR);
	}

	public static int dijkstras(int source, int dest) {

		// Stores array of distance estimates for dijkstra's
		edge[] best = new edge[n+1];
		Arrays.fill(best, null);
		best[0] = new edge(0, 0);

		// Use pq for efficient identification of next best vertex.
		PriorityQueue<edge> pq = new PriorityQueue<edge>();
		pq.offer(best[0]);

		while (pq.size() > 0) {

			// Get next edge - return if we made it.
			edge next = pq.poll();
			if (next.v == dest) return next.w;

			// Enqueue neighbors of next, if necessary.
			for (edge e: (ArrayList<edge>)graph[next.v]) {
				if (best[e.v] == null || next.w + e.w < best[e.v].w) {
					best[e.v] = new edge(e.v, next.w + e.w);
					pq.offer(best[e.v]);
				}
			}
		}

		// If we get here, we never made it!
		return -1;
	}
}

class edge implements Comparable<edge> {

	public int v;
	public int w;

	public edge(int dest, int weight) {
		v = dest;
		w = weight;
	}

	public int compareTo(edge other) {
		return this.w - other.w;
	}

	public String toString() {
		return "to "+v+" w = "+w;
	}
}