1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>

using namespace std;

#define st first
#define nd second
#define pb push_back
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define irep(i,a,b) for(int i = a; i >= b; i--)
typedef long long ll;
typedef long double ld;
//typedef __int128 int128;
typedef vector<int> vi;
typedef pair<int,int> pi; 
typedef pair<double,double> pd;
typedef pair<ll,ll> pl;

const int max_n = 107;
ll p[max_n];
vector<pl> g[max_n];
set<ll> odw[max_n];

void dfs(ll v, ll val){
    //cout << "v: " << v << " val: " << val << '\n';
    for(auto x:g[v]){
        ll new_val = val*x.nd;
        if(new_val > p[x.st] || odw[x.st].count(new_val)) continue;
        odw[x.st].insert(new_val);
        dfs(x.st,new_val);
    }
}

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    int t; cin >> t;
    while(t--){
        int n,m; cin >> n >> m;
        rep(i,1,n) cin >> p[i];
        rep(i,1,m){
            ll a,b,c; cin >> a >> b >> c;
            g[a].pb({b,c});
        }
        dfs(1,1);
        ll ans = -1; if(!odw[n].empty()) ans = *(--odw[n].end());
        cout << ans << '\n';

        rep(i,1,n){
            g[i].clear();
            odw[i].clear();
        }
    }

    return 0;
}

//g++ -O3 -static -Wall .cpp -std=c++17