/*
  [BAPC'07] CYCLING
  by: Jan Kuipers
*/

using namespace std;

#include <iostream>
#include <queue>

int main () {

  int runs;
  cin>>runs;
  while (runs--) {

    int N,M;
    cin>>N>>M;

    vector<int> h(N);
    for (int i=0; i<N; i++) cin>>h[i];

    vector<vector<int> > to(N);
    vector<vector<int> > len(N);
    
    for (int i=0; i<M; i++) {
      int a,b,l;
      cin>>a>>b>>l;
      a--; b--;
      to[a].push_back(b);
      to[b].push_back(a);
      len[a].push_back(l);
      len[b].push_back(l);
    }

    int besth=INT_MAX, bestdist=INT_MAX;
    vector<int> path;
    
    for (int i=0; i<N; i++) {
      int minh = h[i];
      int maxhlo = minh, maxhhi = INT_MAX/2;
      while (maxhlo != maxhhi) {
	int maxh = (maxhlo+maxhhi)/2;

	priority_queue<pair<int,pair<int,int> > > pq;
	pq.push(make_pair(0,make_pair(0,-1)));

	vector<int> dist(N,-1), prev(N);
	while (!pq.empty()) {
	  int d = -pq.top().first;
	  int n = pq.top().second.first;
	  int p = pq.top().second.second;
	  pq.pop();
	  
	  if (h[n]<minh || h[n]>maxh) continue;
	  if (dist[n]!=-1) continue;
	  dist[n]=d;
	  prev[n]=p;

	  for (int j=0; j<len[n].size(); j++)
	    pq.push(make_pair(-(d+len[n][j]),make_pair(to[n][j],n)));
	}

	if (dist[N-1]==-1)
	  maxhlo=maxh+1;
	else {
	  maxhhi=maxh;

	  if (maxh-minh<besth || (maxh-maxh==besth && dist[N-1]<bestdist)) {
	    besth = maxh-minh;
	    bestdist = dist[N-1];

	    int n=N-1;
	    path.clear();
	    while (n!=-1) {
	      path.push_back(n);
	      n=prev[n];
	    }

	    reverse(path.begin(),path.end());
	  }
	}	  
      }
    }

    cout<<besth<<" "<<bestdist<<endl;
  }
  
  return 0;
}
