#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)),(v).end())
typedef pair<int,int> PII;
typedef vector<int> VI;

#define MAXN 100

int dist[MAXN][MAXN];
int alt[MAXN];
VI path[MAXN];

int n;

PII calcpath(int min_alt, int max_alt)
{
	if( alt[0] < min_alt || alt[0] > max_alt ||
	    alt[n-1] < min_alt || alt[n-1] > max_alt ) {
		return make_pair(INT_MAX,INT_MAX);
	}

	priority_queue<PII> Q;
	Q.push(PII(0,0));

	VI curdist(n,INT_MAX);
	curdist[0] = 0;

	while( !Q.empty() ) {
		int curlen = -Q.top().first;
		int curpos = Q.top().second;
		Q.pop();

		if( curpos == n-1 ) return PII(max_alt-min_alt, curlen);

		for( int i = 0; i < path[curpos].size(); ++i ) {
			int to = path[curpos][i];
			if( alt[to] < min_alt || alt[to] > max_alt ) continue;
			int len = curlen+dist[curpos][to];
			if( len < curdist[to] ) {
				curdist[to] = len;
				Q.push(PII(-len,to));
			}
		}
	}

	return PII(INT_MAX,INT_MAX);
}

void run()
{
	memset(dist,0,sizeof(dist));
	memset(alt,0,sizeof(alt));

	VI all_alt;

	int m;

	scanf("%d%d",&n,&m);

	for( int i = 0; i < n; ++i ) {
		scanf("%d",&alt[i]);
		all_alt.push_back(alt[i]);
		path[i].clear();
	}
	SORT(all_alt);
	UNIQUE(all_alt);

	for( int i = 0; i < m; ++i ) {
		int a,b,c; scanf("%d%d%d",&a,&b,&c);
		--a; --b;
		path[a].push_back(b);
		path[b].push_back(a);
		if( dist[a][b] == 0 || dist[a][b] > c ) {
			dist[a][b] = c;
			dist[b][a] = c;
		}
	}

	for( int i = 0; i < n; ++i ) {
		SORT(path[i]);
		UNIQUE(path[i]);
	}

	PII best = make_pair(INT_MAX,INT_MAX);

	for( int i = 0; i < all_alt.size(); ++i ) {
		for( int j = i; j < all_alt.size(); ++j ) {
			if( all_alt[j] - all_alt[i] > best.first ) continue;
			PII cur = calcpath(all_alt[i],all_alt[j]);
			if( cur < best ) best = cur;
		}
	}

	printf("%d %d\n", best.first, best.second);
}

int main()
{
	int t; scanf("%d",&t);
	while( t-- ) run();
	return 0;
}

