#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define PB push_back
#define SZ(v) ((int)(v).size())
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define REPSZ(i,v) REP(i,SZ(v))

typedef pair<int,int> PII;
typedef vector<PII> VPII;

int n,m;
int h[100];
VPII e[100];


void run() {
	scanf("%d%d",&n,&m);
	REP(i,n) scanf("%d",&h[i]);
	REP(i,n) e[i].clear(); REP(j,m) { int a,b,c; scanf("%d%d%d",&a,&b,&c); --a,--b; e[a].PB(MP(b,c)); e[b].PB(MP(a,c)); }
	
	vector<int> allh; REP(i,n) allh.PB(h[i]); sort(allh.begin(),allh.end()); allh.erase(unique(allh.begin(),allh.end()),allh.end());
	
	int besth=INT_MAX,bestd=INT_MAX;
	REPSZ(i,allh) {
		int minh=allh[i];
		int ll=i-1,hh=SZ(allh);
		while(hh-ll>1) {
			int mm=ll+(hh-ll)/2,maxh=allh[mm];
			vector<int> best(n,INT_MAX),prev(n,-1); priority_queue<PII> q;
			if(minh<=h[0]&&h[0]<=maxh) best[0]=0,prev[0]=-2,q.push(MP(-0,0));
			while(!q.empty()) {
				int d=-q.top().first,at=q.top().second; q.pop();
				if(d>best[at]) continue;
//				printf("%d %d: %d (%d)\n",minh,maxh,at,d);
				REPSZ(j,e[at]) {
					int to=e[at][j].first,nd=d+e[at][j].second;
					if(minh<=h[to]&&h[to]<=maxh&&nd<best[to]) best[to]=nd,prev[to]=at,q.push(MP(-nd,to));
				}
			}
			if(best[n-1]!=INT_MAX) {
				hh=mm;
				if(maxh-minh<besth||maxh-minh==besth&&best[n-1]<bestd) besth=maxh-minh,bestd=best[n-1];
			} else {
				ll=mm;
			}
		}
	}
	printf("%d %d\n",besth,bestd);
}

int main() {
	int n; scanf("%d",&n); FORE(i,1,n) run();
	return 0;
}
	
