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
60
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = a; i < b;++i)
#define pb push_back
#define int long long
#define pi pair<int,int>
#define f first
#define s second
using namespace std;
const int maxn = 105;
int maks[maxn];
vector<pi> V[maxn];
unordered_map<int,int> mapa[maxn];
void solve(){
    int n,m;
    cin>>n >>m;
    FOR(i,1,n + 1){
        cin>>maks[i];
    }
    FOR(i,0,m){
        int a,b,c;
        cin>>a >>b >>c;
        V[a].pb({b,c});
    }
    mapa[1][1] = 1;
    queue<pi> Q;
    Q.push({1,1});
    int q = 1;
    int maksi = -1;
    while(!Q.empty()){
        auto x = Q.front();
        Q.pop();
        for(auto y : V[x.f]){
            if(maks[y.f] >= (x.s * y.s) && mapa[y.f].find(y.s * x.s) == mapa[y.f].end()){
                mapa[y.f][y.s * x.s] = 1;
                Q.push({y.f,y.s * x.s});
                if(y.f == n){
                    maksi = max(maksi,y.s * x.s);
                }
            }
        }
    }
    if(n == 1){
        maksi = max(maksi,q);
    }
    cout<<maksi <<"\n";
    FOR(i,0,n + 1){
        V[i].clear();
        mapa[i].clear();
        maks[i] = 0;
    }
}
int32_t main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    FOR(i,0,n){
        solve();
    }
}