//  Created by TaoSama.
//  Copyright (c) 2017 TaoSama. All rights reserved.
//
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int main(){
#ifdef LOCAL
    freopen("/Users/didi/ACM/in.txt", "r", stdin);
//  freopen("/Users/didi/ACM/out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0); cin.tie(0);

    int t; scanf("%d", &t);
    while(t--) {
        int n; scanf("%d", &n);
        for(int i = 1; i <= n; ++i) {
            int x; scanf("%d", &x);
        }
        puts("YES");
        for(int i = 1; i <= n; ++i) printf("%d%c", i, " \n"[i == n]);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        long long a[n];
        bool diff[2000000];
        long long b[n];
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        for (int i=0; i<n; i++) {
            for (int j=i; j<n; j++) {
                diff[abs(a[i]-a[j])]=true;
            }
        }
        b[0]=1;
        long long j=2;
        long long k=1;
        while (k<n){
            bool flag=true;
            for (int i=0; i<k;i++) {
                    if (diff[j-b[i]]==true) {
                        flag =false;
                        break;
                    }
            }
            if (flag) {
                b[k]=j;
                k++;
            }
            j++;
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        long long a[n];
        bool diff[1000500];
        long long b[n];
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        for (int i=0; i<n; i++) {
            for (int j=i+1;j<n;j++) {
                diff[abs(a[i]-a[j])]=true;
            }
        }
        b[0]=1;
        long long j=2;
        long long k=1;
        while (k<n){
            bool flag=true;
            for (int i=0; i<k;i++) {
                    if (diff[j-b[i]]==true) {
                        flag =false;
                        break;
                    }
            }
            if (flag) {
                b[k]=j;
                k++;
            }
            j++;
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        int a[n];
        bool diff[1111111]={false};
        int b[n];
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        sort(a,a+n);
        for (int i=0; i<n; i++) {
            for (int j=i+1;j<n;j++) {
                diff[a[j]-a[i]]=true;
            }
        }
        b[0]=1;
        int j=2;
        int k=1;
        while (k<n){
            bool flag=true;
            for (int i=0; i<k;i++) {
                    if (diff[j-b[i]]==true) {
                        flag =false;
                        break;
                    }
            }
            if (flag) {
                b[k]=j;
                k++;
            }
            j++;
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <set>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        long long a[n];
        bool diff[1000000];
        long long b[n];
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        for (int i=0; i<n; i++) {
            for (int j=i; j<n; j++) {
                diff[abs(a[i]-a[j])]=true;
            }
        }
        b[0]=1;
        long long j=2;
        long long k=1;
        while (k<n){
            bool flag=true;
            for (int i=0; i<k;i++) {
                    if (diff[j-b[i]]==1){
                        flag =false;
                        break;
                    }
            }
            if (flag) {
                b[k]=j;
                k++;
            }
            j++;
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        long long a[n];
        bool diff[1111111]={false};
        long long b[n];
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        sort(a,a+n);
        for (int i=0; i<n; i++) {
            for (int j=i+1;j<n;j++) {
                diff[a[j]-a[i]]=true;
            }
        }
        b[0]=1;
        long long j=2;
        long long k=1;
        while (k<n){
            bool flag=true;
            for (int i=0; i<k;i++) {
                    if (diff[j-b[i]]==true) {
                        flag =false;
                        break;
                    }
            }
            if (flag) {
                b[k]=j;
                k++;
            }
            j++;
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <set>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        long long a[n];
        set<long long> sums;
        vector<long long> b;
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        b.push_back(1);
        long long j=2;
        for (int i=0; i<n; i++) {
            sums.insert(a[i]+1);
        }
        while (b.size()<n){
            int tr=0;
            for (int i=0; i<n;i++) {
                    if (sums.insert(a[i]+j).second!=1) {
                        for (int k=0; k<i-1; k++)sums.erase(sums.end());
                        j++;
                        break;
                    }
                    else tr++;
            }
            if (tr==n) {
                b.push_back(j);
                j++;
            }
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        long long a[n];
        bool diff[1000000];
        long long b[n];
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        for (int i=0; i<n; i++) {
            for (int j=i; j<n; j++) {
                diff[abs(a[i]-a[j])]=true;
            }
        }
        b[0]=1;
        long long j=2;
        long long k=1;
        while (k<n){
            bool flag=true;
            for (int i=0; i<k;i++) {
                    if (diff[j-b[i]]){
                        flag =false;
                        break;
                    }
            }
            if (flag) {
                b[k]=j;
                k++;
            }
            j++;
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <set>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        long long a[n];
        bool sums[2000000];
        long long b[n];
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        b[0]=1;
        long long j=2;
        long long k=1;
        for (int i=0; i<n; i++) {
            sums[a[i]+1]=1;
        }
        while (k<n){
            bool flag=true;
            for (int i=0; i<n;i++) {
                    if (sums[a[i]+j]==1) {
                        flag =false;
                        break;
                    }
                    else{
                        sums[a[i]+j]=1;
                    }
            }
            if (flag) {
                b[k]=j;
                k++;
            }
            j++;
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <set>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        long long a[n];
        bool sums[2000000];
        long long b[n];
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        b[0]=1;
        long long j=2;
        long long k=1;
        for (int i=0; i<n; i++) {
            sums[a[i]+1]=1;
        }
        while (k<n){
            int tr=0;
            for (int i=0; i<n;i++) {
                    if (sums[a[i]+j]==1) {
                        break;
                    }
                    else{
                        tr++;
                        sums[a[i]+j]=1;
                    }
            }
            if (tr==n) {
                b[k]=j;
                k++;
            }
            j++;
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        long long a[n];
        bool diff[1111111]={false};
        long long b[n];
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        for (int i=0; i<n; i++) {
            for (int j=i+1;j<n;j++) {
                if (a[i]>a[j])diff[a[i]-a[j]]=true;
                else diff[a[j]-a[i]]=true;
            }
        }
        b[0]=1;
        long long j=2;
        long long k=1;
        while (k<n){
            bool flag=true;
            for (int i=0; i<k;i++) {
                    if (diff[j-b[i]]==true) {
                        flag =false;
                        break;
                    }
            }
            if (flag) {
                b[k]=j;
                k++;
            }
            j++;
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        long long a[n];
        bool diff[1000500];
        long long b[n];
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        for (int i=0; i<n; i++) {
            for (int j=i; j<n; j++) {
                diff[abs(a[i]-a[j])]=true;
            }
        }
        b[0]=1;
        long long j=2;
        long long k=1;
        while (k<n){
            bool flag=true;
            for (int i=0; i<k;i++) {
                    if (diff[j-b[i]]==true) {
                        flag =false;
                        break;
                    }
            }
            if (flag) {
                b[k]=j;
                k++;
            }
            j++;
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <set>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t>0) {
        int n;
        cin>>n;
        long long a[n];
        bool sums[2000000];
        vector<long long> b;
        for (int i=0; i<n; i++) {
            cin>>a[i];
        }
        b.push_back(1);
        long long j=2;
        for (int i=0; i<n; i++) {
            sums[a[i]+1]=1;
        }
        while (b.size()<n){
            int tr=0;
            for (int i=0; i<n;i++) {
                    if (sums[a[i]+j]==1) {
                        j++;
                        break;
                    }
                    else{
                        tr++;
                        sums[a[i]+j]=1;
                    }
            }
            if (tr==n) {
                b.push_back(j);
                j++;
            }
        }
        cout<<"YES"<<'\n';
        for (int i=0; i<n; i++) {
            cout<<b[i]<<' ';
        }
        cout<<'\n';
        t--;
    }
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int a[105], b[105];
bool vis[1000005];
int main()
{
	// freopen("856A.in", "r", stdin);
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n;
		scanf("%d", &n);
		for (int i = 0; i < n; i++)
			scanf("%d", a + i);
		sort(a, a + n);
		memset(vis, false, sizeof(vis));
		for (int i = 0; i < n; i++)
		{
			for (int j = i + 1; j < n; j++)
				vis[a[j] - a[i]] = true;
		}
		int cur = 0;
		for (int i = 1; i <= 1000000 && cur < n; i++)
		{
			bool f = true;
			for (int j = 0; j < cur && f; j++)
			{
				if (vis[i - b[j]])
					f = false;
			}
			if (f)
				b[cur++] = i;
		}
		if (cur >= n)
		{
			printf("YES\n");
			for (int i = 0; i < n; i++)
				printf("%d%c", b[i], " \n"[i + 1 == n]);
		}
		else
			printf("NO\n");
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int a[105], b[105];
bool vis[1000005];
int main()
{
	// freopen("856A.in", "r", stdin);
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n;
		scanf("%d", &n);
		for (int i = 0; i < n; i++)
			scanf("%d", a + i);
		sort(a, a + n);
		memset(vis, false, sizeof(vis));
		for (int i = 0; i < n; i++)
		{
			for (int j = i + 1; j < n; j++)
				vis[a[j] - a[i]] = true;
		}
		int cur = 0;
		for (int i = 1; i <= 1000000 && cur < n; i++)
		{
			bool f = true;
			for (int j = 0; j < cur && f; j++)
			{
				if (vis[i - b[j]])
					f = false;
			}
			if (f)
				b[cur++] = i;
		}
		if (cur >= n)
		{
			printf("YES\n");
			for (int i = 0; i < n; i++)
				printf("%d%c", b[i], " \n"[i + 1 == n]);
		}
		else
			printf("NO\n");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    //fast;
    int t; scanf("%d", &t);
    while(t--) {
        int n; scanf("%d", &n);

        int A[n];
        vector<int> diff_A;
        vector<int> B;
        bool nope[1000001] = {0};

        for (int i = 0; i < n; i++)
            scanf("%d", &A[i]);

        sort(A, A + n);
        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++)
                diff_A.push_back(A[j] - A[i]);

        printf("YES\n");
        int cnt = 0;
        for(int i = 1; i < 1000001; i++){
            if(nope[i]) continue;
            if(cnt == n) break;

            for(auto x : diff_A)
                nope[x + i] = 1;
            cnt++;
            printf("%d ", i);
        }
        printf("\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    fast;
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;

        int A[n];
        vector<int> diff_A;
        vector<int> B;
        bool nope[1000001] = {0};

        for (int i = 0; i < n; i++)
            cin >> A[i];

        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++)
                diff_A.push_back(abs(A[i] - A[j]));

        cout << "YES\n";
        int cnt = 0;
        for(int i = 1; i < 1000001; i++){
            if(nope[i]) continue;
            if(cnt == n) break;

            for(auto x : diff_A)
                nope[x + i] = 1;
            cnt++;
            cout << i << " ";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    fast;
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;

        int A[n];
        vector<int> diff_A;
        vector<int> B;
        bool nope[1000001] = {0};

        for (int i = 0; i < n; i++)
            cin >> A[i];

        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++)
                diff_A.push_back(abs(A[i] - A[j]));

        cout << "YES\n";
        for(int i = 1; i < 1000001; i++){
            if(nope[i]) continue;
            if(B.size() == n) break;

            for(auto x : diff_A)
                nope[x + i] = 1;

            cout << i << " ";
        }
        cout << endl;
    }
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
map<int, bool> used;
int main() {
    int t; cin >> t;
    while(t--){
        int n; cin >> n;

        cout << "YES\n";
        int st;
        for(int i = 0; i < n; i++){
            int tmp; cin >> tmp;
            used[tmp] = 1;
            st = tmp;
        }

        for(int i = 1, j = 0; j < n && i <= 1000000; i++){
            if(!used[i] || i == st){
                cout << i << " ";
                j++;
            }
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    fast;
    int t; cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int a[n];
        bool diff[1000001] = {0};
        bool nope[1000001] = {0};
        for (int i = 0; i < n; i++)
            cin >> a[i];

        set<int> diff_A;
        vector<int> B;
        B.push_back(1);
        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++)
                diff_A.insert(abs(a[i] - a[j]));

        for(int i = 2; i < 1000001; i++){
            bool ok = !nope[i];
            if(ok != 1) continue;
            if(B.size() == n) break;
            for(auto x : diff_A){
                nope[x + i] = 1;
            }
            if(ok) B.push_back(i);
        }

        if(B.size() == n){
            cout << "YES\n";
            for(auto x : B)
                cout << x << " ";
            cout << endl;
        }
        else cout << "NO\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    fast;
    int t; cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int a[n];
        bool diff[1000001] = {0};
        for (int i = 0; i < n; i++)
            cin >> a[i];

        set<int> diff_A;
        set<int> B;
        B.insert(1);
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                diff[abs(a[i] - a[j])] = 1;

        for(int i = 2; i < 1000001; i++){
            bool ok = 1;
            if(B.size() == n) break;
            for(auto x : B){
                if(diff[abs(x - i)]){
                    ok = 0;
                    break;
                }
            }
            if(ok) B.insert(i);
        }

        if(B.size() == n){
            cout << "YES\n";
            for(auto x : B)
                cout << x << " ";
            cout << endl;
        }
        else cout << "NO\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    fast;
    int t; cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int a[n];
        bool diff[1000001];
        for (int i = 0; i < n; i++)
            cin >> a[i];

        set<int> diff_A;
        set<int> B;
        B.insert(1);
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                diff[abs(a[i] - a[j])] = 1;

        for(int i = 2; i < 1000001; i++){
            bool ok = 1;
            if(B.size() == n) break;
            for(auto x : B){
                if(diff[(abs(x - i))]){
                    ok = 0;
                    break;
                }
            }
            if(ok) B.insert(i);
        }

        if(B.size() == n){
            cout << "YES\n";
            for(auto x : B)
                cout << x << " ";
            cout << endl;
        }
        else cout << "NO\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    //fast;
    int t; scanf("%d", &t);
    while(t--) {
        int n; scanf("%d", &n);

        int A[n];
        vector<int> diff_A;
        vector<int> B;
        bool nope[1000001] = {0};

        for (int i = 0; i < n; i++)
            scanf("%d", &A[i]);

        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++)
                diff_A.push_back(abs(A[i] - A[j]));

        printf("YES\n");
        int cnt = 0;
        for(int i = 1; i < 1000001; i++){
            if(nope[i]) continue;
            if(cnt == n) break;

            for(auto x : diff_A)
                nope[x + i] = 1;
            cnt++;
            printf("%d ", i);
        }
        printf("\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    fast;
    int t; cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int a[n];
        for (int i = 0; i < n; i++)
            cin >> a[i];

        set<int> sums;
        set<int> ans;
        for (int j = 1; j <= 1000000; j++) {
            int ok = 1;
            if (ans.size() == n) break;
            for (int x = 0; x < n; x++) {
                if (sums.count(a[x] + j) != 0) {
                    ok = 0;
                    break;
                }
            }
            if (ok) {
                ans.insert(j);
                for (int x = 0; x < n; x++)
                    sums.insert(a[x] + j);
            }
        }

        if (ans.size()) {
            cout << "YES\n";
            for (auto x : ans)
                cout << x << " ";
        } else cout << "NO";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    fast;
    int t; cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int a[n];
        bool diff[1000001] = {0};
        bool nope[1000001] = {0};
        for (int i = 0; i < n; i++)
            cin >> a[i];

        set<int> diff_A;
        vector<int> B;
        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++)
                diff_A.insert(abs(a[i] - a[j]));

        for(int i = 1; i < 1000001; i++){
            bool ok = !nope[i];
            if(ok != 1) continue;
            if(B.size() == n) break;
            for(auto x : diff_A){
                nope[x + i] = 1;
            }
            if(ok) B.push_back(i);
        }

        if(B.size() == n){
            cout << "YES\n";
            for(auto x : B)
                cout << x << " ";
            cout << endl;
        }
        else cout << "NO\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    fast;
    int t; cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int a[n];
        bool diff[1000001] = {0};
        for (int i = 0; i < n; i++)
            cin >> a[i];

        set<int> diff_A;
        vector<int> B;
        B.push_back(1);
        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++)
                diff[abs(a[i] - a[j])] = 1;

        for(int i = 2; i < 100001; i++){
            bool ok = 1;
            if(B.size() == n) break;
            for(auto x : B){
                if(diff[abs(x - i)]){
                    ok = 0;
                    break;
                }
            }
            if(ok) B.push_back(i);
        }

        if(B.size() == n){
            cout << "YES\n";
            for(auto x : B)
                cout << x << " ";
            cout << endl;
        }
        else cout << "NO\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    fast;
    int t; cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int a[n];
        for (int i = 0; i < n; i++)
            cin >> a[i];

        set<int> diff_A;
        set<int> B;
        B.insert(1);
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                diff_A.insert(abs(a[i] - a[j]));

        for(int i = 2; i < 1000001; i++){
            bool ok = 1;
            if(B.size() == n) break;
            for(auto x : B){
                if(diff_A.count(abs(x - i))){
                    ok = 0;
                    break;
                }
            }
            if(ok) B.insert(i);
        }

        if(B.size() == n){
            cout << "YES\n";
            for(auto x : B)
                cout << x << " ";
            cout << endl;
        }
        else cout << "NO\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;

int main () {
    fast;
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;

        int A[n];
        set<int> diff_A;
        vector<int> B;
        bool nope[1000001] = {0};

        for (int i = 0; i < n; i++)
            cin >> A[i];

        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++)
                diff_A.insert(abs(A[i] - A[j]));

        for(int i = 1; i < 1000001; i++){
            if(nope[i]) continue;
            if(B.size() == n) break;

            for(auto x : diff_A)
                nope[x + i] = 1;

            B.push_back(i);
        }

        cout << "YES\n";
        for(auto x : B)
            cout << x << " ";
        cout << endl;
    }
}


#include <bits/stdc++.h>
#include <unordered_map>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll cel(ll x,ll y){
    if(x%y==0)return x/y;
    return x/y+1;
}
ll POW(ll x,ll y){
    if(y==0)return 1;
    if(y==1)return x;
    ll ans=POW(x,y/2);
    ans*=ans;
    if(y%2==0)return ans;
    return ans*x;
}
const int MX=1e5+9;
const ll mod=1e9+7;
const ll inf=1e18;
int t,n,a[MX],mn,mx;
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        vector<int>res;
        bool m[MX]={0};
        for(int i=1;i<=1e6;i++){
            bool ok=1;
            for(int j=0;j<n;j++){
                if(m[a[j]+i])ok=0;
            }
            if(!ok)continue;
            res.push_back(i);
            for(int j=0;j<n;j++)m[a[j]+i]=1;
            if(res.size()==n)break;
        }
        if(res.size()!=n){
            puts("NO");
            continue;
        }
        puts("YES");
        for(auto pp:res)cout<<pp<<" ";
        cout<<endl;
    }
}


#include <bits/stdc++.h>
#include <unordered_map>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll cel(ll x,ll y){
    if(x%y==0)return x/y;
    return x/y+1;
}
ll POW(ll x,ll y){
    if(y==0)return 1;
    if(y==1)return x;
    ll ans=POW(x,y/2);
    ans*=ans;
    if(y%2==0)return ans;
    return ans*x;
}
const int MX=1e5+9;
const ll mod=1e9+7;
const ll inf=1e18;
int t,n,a[MX],mn,mx;
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        bool m[MX]={0};
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                m[a[j]-a[i]]=1;
            }
        }
        int x=-1;
        for(int i=1;i<=1000000;i++){
            if(!m[i]){x=i;break;}
        }
        vector<int>res;
        for(int i=1,j=0;i<=1000000&&j<n;i+=x,j++){
            res.push_back(i);
        }
        if(res.size()!=n){
            puts("NO");
            continue;
        }
        puts("YES");
        for(auto pp:res)cout<<pp<<" ";
        cout<<endl;
    }
}


#include <bits/stdc++.h>
#include <unordered_map>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll cel(ll x,ll y){
    if(x%y==0)return x/y;
    return x/y+1;
}
ll POW(ll x,ll y){
    if(y==0)return 1;
    if(y==1)return x;
    ll ans=POW(x,y/2);
    ans*=ans;
    if(y%2==0)return ans;
    return ans*x;
}
const int MX=2e6+100;
const ll mod=1e9+7;
const ll inf=1e18;
int t,n,a[MX],mn,mx;
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        vector<int>res;
        bool m[MX]={0};
        for(int i=1;i<=1e6;i++){
            bool ok=1;
            for(int j=0;j<n;j++){
                if(m[a[j]+i])ok=0;
            }
            if(!ok)continue;
            res.push_back(i);
            for(int j=0;j<n;j++)m[a[j]+i]=1;
            if(res.size()==n)break;
        }
        if(res.size()!=n){
            puts("NO");
            continue;
        }
        puts("YES");
        for(auto pp:res)cout<<pp<<" ";
        cout<<endl;
    }
}


#include <bits/stdc++.h>
#include <unordered_map>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll cel(ll x,ll y){
    if(x%y==0)return x/y;
    return x/y+1;
}
ll POW(ll x,ll y){
    if(y==0)return 1;
    if(y==1)return x;
    ll ans=POW(x,y/2);
    ans*=ans;
    if(y%2==0)return ans;
    return ans*x;
}
const int MX=1e6+9;
const ll mod=1e9+7;
const ll inf=1e18;
int t,n,a[MX],mn,mx;
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        vector<int>res;
        bool m[MX]={0};
        for(int i=1;i<=1e6;i++){
            bool ok=1;
            for(int j=0;j<n;j++){
                if(m[a[j]+i])ok=0;
            }
            if(!ok)continue;
            res.push_back(i);
            for(int j=0;j<n;j++)m[a[j]+i]=1;
            if(res.size()==n)break;
        }
        if(res.size()!=n){
            puts("NO");
            continue;
        }
        puts("YES");
        for(auto pp:res)cout<<pp<<" ";
        cout<<endl;
    }
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

//Author: Jiangsu Nanjing Li Zongtai
//强壮标记*10000,手牌*10000,血量10000 lyl+hzj也打不死我哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈~~~~
//注意要不要long long

const int inf=2147483647;

void solve()
{
	int n;
	cin>>n;

	int a[111];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}

	sort(a+1,a+n+1);

	int nw=1e6;

	for(int i=2;i<=n;i++)
	{
		nw=min(nw,a[i]-a[i-1]);
	}

	if(nw>=n)
	{
		cout<<"YES"<<endl;
		for(int i=1;i<=n;i++) cout<<i<<' ';
		cout<<endl;
		return;
	}

	int mx=a[n];

	if((n-1)*mx+1<=1e6)
	{
		cout<<"YES"<<endl;
		for(int i=1;i<=n;i++) cout<<(i-1)*mx+1<<' ';
		cout<<endl;

		return;
	}

	cout<<"NO"<<endl;
	return;
}

int main()
{
	int T;
	cin>>T;

	while(T--)
	{
		solve();
	}

	return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

//Author: Jiangsu Nanjing Li Zongtai
//强壮标记*10000,手牌*10000,血量10000 lyl+hzj也打不死我哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈~~~~
//注意要不要long long

const int inf=2147483647;

int n;
int a[111];
bool used[2222222];
int ans[111];
int ansn;
bool haveans;

void dfs(int pos,int num)
{
	if(pos>n)
	{
		cout<<"YES"<<endl;
		for(int i=1;i<=ansn;i++) cout<<ans[i]<<' ';
		cout<<endl;

		haveans=1;

		return;
	}

	for(int i=num;i<=1e6;i++)
	{
		bool flag=0;
		for(int j=1;j<=n;j++)
		{
			if(used[a[j]+i])
			{
				flag=1;
				break;
			}
		}

		if(!flag)
		{
			for(int j=1;j<=n;j++)
			{
				used[a[j]+i]=1;
			}

			ansn++;
			ans[ansn]=i;

			dfs(pos+1,i);

			if(haveans) return;

			ansn--;

			for(int j=1;j<=n;j++)
			{
				used[a[j]+i]=0;
			}
		}
	}
}

void solve()
{
	cin>>n;

	for(int i=1;i<=n;i++) cin>>a[i];

	memset(used,0,sizeof(used));
	ansn=0;
	haveans=0;

	dfs(1,1);

	if(!haveans) cout<<"NO"<<endl;

	return;
}

int main()
{
	int T;
	cin>>T;

	while(T--)
	{
		solve();
	}

	return 0;
}


#include <iostream>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;

int a[200], b[200];

void solve() {
	set<int> s, f;
	int N, cnt = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		for (int j = 0; j < i; j++) {
			f.insert(abs(a[i] - a[j]));
		}
	}

	for (int v = 1; v <= 1000 * 1000; ++v ) {
		int db = (cnt == 0 ? 0 : (v - b[cnt - 1]));
		if (f.count(db)) {
			continue;
		}
		bool flag = true;
		for (int i = 0; i < N && flag; ++i) {
			if (s.count(a[i] + v)) {
				flag = false;
			}
		}
		if (flag) {
			for (int i = 0; i < N; ++i) {
				s.insert(v + a[i]);
			}
			b[cnt++] = v;

			if (cnt == N) {
				break;
			}
		}
	}
	if (cnt == N) {
		printf("YES\n");
		for (int i = 0; i < cnt; ++i) {
			printf("%d ", b[i]);
		}
		printf("\n");
		return;
	}
	throw 100500;
	return;
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		solve();
	}
}

/*#include<iostream>
#include <cstdio>

using namespace std;

const int MOD = 998244353;

long long dp[2010][20];
int ar[110];

void solve()
{
	memset(dp, 0, 2010 * 20 * 8);
	dp[0][0] = 1;
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &ar[i]);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 11; j++)
		{

		}
	}
	printf("%d\n", dp[n][0]);
}

int main()
{
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++)
		solve();
	return 0;
}

*/


#include <iostream>
#include <set>
#include <cstdio>
using namespace std;

int a[200], b[200];

void solve() {
	set<int> s;
	int N, cnt = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}
	for (int v = 1; v <= 1000 * 1000; ++v) {
		bool flag = true;
		for (int i = 0; i < N && flag; ++i) {
			if (s.count(a[i] + v)) {
				flag = false;
			}
		}
		if (flag) {
			for (int i = 0; i < N; ++i) {
				s.insert(v + a[i]);
			}
			b[cnt++] = v;
			if (cnt == N) {
				break;
			}
		}
	}
	if (cnt == N) {
		printf("YES\n");
		for (int i = 0; i < cnt; ++i) {
			printf("%d ", b[i]);
		}
		printf("\n");
		return;
	}
	throw 100500;
	return;
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		solve();
	}
}

/*#include<iostream>
#include <cstdio>

using namespace std;

const int MOD = 998244353;

long long dp[2010][20];
int ar[110];

void solve()
{
	memset(dp, 0, 2010 * 20 * 8);
	dp[0][0] = 1;
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &ar[i]);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 11; j++)
		{

		}
	}
	printf("%d\n", dp[n][0]);
}

int main()
{
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++)
		solve();
	return 0;
}

*/


#include <iostream>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;

int a[200], b[200];
const int SIZE = 2 * 1000 * 1000 + 5;
bool flag[SIZE];

void solve() {
	set<int> s, f;
	int N, cnt = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		for (int j = 0; j < i; j++) {
			f.insert(abs(a[i] - a[j]));
		}
	}
	int nextFree = 1;
	int mm = 0;
	for (int i = 0; i < N; ++i) {
		int v = b[cnt++] = nextFree;
		int dv = (cnt >= 2) ? (v - b[cnt - 2]) : 0;
		f.insert(dv);
		if (dv) {
			for (int j = 0; j < cnt; ++j) {
				flag[b[j] + dv] = true;
			}
		}
		nextFree++;
		for (auto& x : f) {
			if (v + x < SIZE) {
				flag[v + x] = true;
				mm = max(mm, v + x);
			}
		}
		while (flag[nextFree]) {
			nextFree++;
		}
	}
	for (int i = 0; i <= mm; ++i) {
		flag[mm] = false;
	}
	if (cnt == N) {
		printf("YES\n");
		for (int i = 0; i < cnt; ++i) {
			printf("%d ", b[i]);
		}
		printf("\n");
		return;
	}
	throw 100500;
	return;
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		solve();
	}
}

/*#include<iostream>
#include <cstdio>

using namespace std;

const int MOD = 998244353;

long long dp[2010][20];
int ar[110];

void solve()
{
	memset(dp, 0, 2010 * 20 * 8);
	dp[0][0] = 1;
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &ar[i]);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 11; j++)
		{

		}
	}
	printf("%d\n", dp[n][0]);
}

int main()
{
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++)
		solve();
	return 0;
}

*/


#include <iostream>
#include <set>
#include <cstdio>
using namespace std;

int a[200], b[200];

void solve() {
	set<int> s;
	int N, cnt = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		for (int j = 0; j < i; ++j) {
			s.insert(abs(a[i] - a[j]));
		}
	}
	int D = -1;
	for (int d = 2; d <= 1000 * 1000; ++d) {
		bool flag = true;
		for (auto& x : s) {
			if (x % d == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			D = d;
			break;
		}
	}
	if (D == -1) {
		throw 200;
	}
	b[cnt++] = 1;
	while (cnt < N) {
		b[cnt] = b[cnt - 1] + D;
		cnt++;
	}

	if (cnt == N) {
		printf("YES\n");
		for (int i = 0; i < cnt; ++i) {
			printf("%d ", b[i]);
		}
		printf("\n");
		return;
	}
	throw 100500;
	return;
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		solve();
	}
}

/*#include<iostream>
#include <cstdio>

using namespace std;

const int MOD = 998244353;

long long dp[2010][20];
int ar[110];

void solve()
{
memset(dp, 0, 2010 * 20 * 8);
dp[0][0] = 1;
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &ar[i]);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 11; j++)
{

}
}
printf("%d\n", dp[n][0]);
}

int main()
{
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++)
solve();
return 0;
}

*/


#include <iostream>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;

int a[200], b[200];
const int SIZE = 2 * 1000 * 1000 + 5;
bool flag[SIZE];

void solve() {
	set<int> s, f;
	int N, cnt = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		for (int j = 0; j < i; j++) {
			f.insert(abs(a[i] - a[j]));
		}
	}
	int nextFree = 1;
	int mm = 0;
	for (int i = 0; i < N; ++i) {
		int v = b[cnt++] = nextFree;
		nextFree++;
		for (auto& x : f) {
			if (v + x < SIZE) {
				flag[v + x] = true;
				mm = max(mm, v + x);
			}
		}
		while (flag[nextFree]) {
			nextFree++;
		}
	}
	for (int i = 0; i <= mm; ++i) {
		flag[mm] = false;
	}
	if (cnt == N) {
		printf("YES\n");
		for (int i = 0; i < cnt; ++i) {
			printf("%d ", b[i]);
		}
		printf("\n");
		return;
	}
	throw 100500;
	return;
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		solve();
	}
}

/*#include<iostream>
#include <cstdio>

using namespace std;

const int MOD = 998244353;

long long dp[2010][20];
int ar[110];

void solve()
{
	memset(dp, 0, 2010 * 20 * 8);
	dp[0][0] = 1;
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &ar[i]);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 11; j++)
		{

		}
	}
	printf("%d\n", dp[n][0]);
}

int main()
{
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++)
		solve();
	return 0;
}

*/


#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3fLL
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
bool vis[1000005];
int num[105];
int main(){
    int T; scanf("%d", &T);
    while (T--){
        int now = 1;
        memset(vis, 0, sizeof(vis));
        int n; scanf("%d", &n);
        for (int i = 0; i < n; i++) scanf("%d", &num[i]);
        printf("YES\n");
        for (int i = 0; i < n; i++){
            while (vis[now]) now++;
            printf("%d ", now);
            for (int j = 0; j < n; j++){
                for (int k = 0; k < n; k++){
                    if (num[j] - num[k] + now >= 0) vis[num[j] - num[k] + now] = 1;
                }
            }
        }
        printf("\n");
    }

}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
int link[N],Size[N];
pair<long long,int> v[N];
vector< tuple<long long,int,int> > edges;

int find(int x)
{
    while (x!=link[x])
        x = link[x];
    return x;
}
void unite(int x, int y)
{
    x = link[x];
    y = link[y];
    if (Size[x]<Size[y])
        swap(x,y);
    Size[x]+=Size[y];
    link[y] = x;
}

int main()
{
    int n,m;
    cin >> n >> m;
    for (int i = 1; i<=n; i++)
    {
        cin >> v[i].first;
        v[i].second = i;
    }
    sort(v+1,v+n+1);
    for (int i = 1; i<=n; i++)
    {
        Size[i] = 1;
        link[i] = i;
    }
    for (int i = 1; i<=n; i++)
    {
        if (i!=1)
            edges.push_back(make_tuple(v[1].first+v[i].first,v[1].second,v[i].second));
        if (i!=2)
            edges.push_back(make_tuple(v[2].first+v[i].first,v[2].second,v[i].second));
    }
    for (int i = 1; i<=m; i++)
    {
        int x,y;
        long long c;
        cin >> x >> y >> c;
        edges.push_back(make_tuple(c,x,y));
    }
    sort(edges.begin(),edges.end());
    long long ans = 0;
    for (auto it: edges)
    {
        long long cost = get<0>(it);
        int x = get<1>(it), y = get<2>(it);
        if (find(x)!=find(y))
        {
            ans+=cost;
            unite(x,y);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
int link[N],Size[N];
pair<long long,int> v[N];
vector< tuple<long long,int,int> > edges;

int find(int x)
{
    while (x!=link[x])
        x = link[x];
    return x;
}
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (Size[x]<Size[y])
        swap(x,y);
    Size[x]+=Size[y];
    link[y] = x;
}

int main()
{
    int n,m;
    cin >> n >> m;
    for (int i = 1; i<=n; i++)
    {
        cin >> v[i].first;
        v[i].second = i;
        link[i] = i;
        Size[i] = 1;
    }
    sort(v+1,v+n+1);
    for (int i = 2; i<=n; i++)
        edges.push_back(make_tuple(v[1].first+v[i].first,v[1].second,v[i].second));
    for (int i = 1; i<=m; i++)
    {
        int x,y,c;
        cin >> x >> y >> c;
        edges.push_back(make_tuple(c,x,y));
    }
    sort(edges.begin(),edges.end());
    long long ans = 0;
    for (auto it: edges)
    {
        long long cost = get<0>(it);
        int x = get<1>(it), y = get<2>(it);
        if (find(x)!=find(y))
        {
            ans+=cost;
            unite(x,y);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
int link[N],Size[N];
pair<long long,int> v[N];
vector< tuple<long long,int,int> > edges;

int find(int x)
{
    while (x!=link[x])
        x = link[x];
    return x;
}
void unite(int x, int y)
{
    x = link[x];
    y = link[y];
    if (Size[x]<Size[y])
        swap(x,y);
    Size[x]+=Size[y];
    link[y] = x;
}

int main()
{
    int n,m;
    cin >> n >> m;
    for (int i = 1; i<=n; i++)
    {
        cin >> v[i].first;
        v[i].second = i;
        link[i] = i;
        Size[i] = 1;
    }
    sort(v+1,v+n+1);
    for (int i = 2; i<=n; i++)
        edges.push_back(make_tuple(v[1].first+v[i].first,v[1].second,v[i].second));
    for (int i = 1; i<=m; i++)
    {
        int x,y,c;
        cin >> x >> y >> c;
        edges.push_back(make_tuple(c,x,y));
    }
    sort(edges.begin(),edges.end());
    long long ans = 0;
    for (auto it: edges)
    {
        long long cost = get<0>(it);
        int x = get<1>(it), y = get<2>(it);
        if (find(x)!=find(y))
        {
            ans+=cost;
            unite(x,y);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
int link[N],Size[N];
long long v[N];
vector< tuple<long long,int,int> > edges;

int find(int x)
{
    while (x!=link[x])
        x = link[x];
    return x;
}
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (Size[x]<Size[y])
        swap(x,y);
    Size[x]+=Size[y];
    link[y] = x;
}

int main()
{
    int n,m;
    cin >> n >> m;
    for (int i = 1; i<=n; i++)
    {
        cin >> v[i];
        Size[i] = 1;
        link[i] = i;
    }
    long long Min = v[1];
    int poz = 1;
    for (int i = 2; i<=n; i++)
        if (v[i]<Min)
        {
            Min = v[i];
            poz = i;
        }
    for (int i = 1; i<=n; i++)
        if (poz!=i)
            edges.push_back(make_tuple(v[i]+v[poz],i,poz));
    for (int i = 1; i<=m; i++)
    {
        int x,y;
        long long c;
        cin >> x >> y >> c;
        edges.push_back(make_tuple(c,x,y));
    }
    sort(edges.begin(),edges.end());
    long long ans = 0;
    for (auto it: edges)
    {
        long long cost = get<0>(it);
        int x = get<1>(it), y = get<2>(it);
        if (find(x)!=find(y))
        {
            ans+=cost;
            unite(x,y);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
int link[N],Size[N];
pair<long long,int> v[N];
vector< tuple<long long,int,int> > edges;

int find(int x)
{
    while (x!=link[x])
        x = link[x];
    return x;
}
void unite(int x, int y)
{
    x = link[x];
    y = link[y];
    if (Size[x]<Size[y])
        swap(x,y);
    Size[x]+=Size[y];
    link[y] = x;
}

int main()
{
    int n,m;
    cin >> n >> m;
    for (int i = 1; i<=n; i++)
    {
        cin >> v[i].first;
        v[i].second = i;
    }
    sort(v+1,v+n+1);
    for (int i = 1; i<=n; i++)
    {
        Size[i] = 1;
        link[v[i].second] = v[i].second;
    }
    for (int i = 2; i<=n; i++)
        edges.push_back(make_tuple(v[1].first+v[i].first,v[1].second,v[i].second));
    for (int i = 1; i<=m; i++)
    {
        int x,y;
        long long c;
        cin >> x >> y >> c;
        edges.push_back(make_tuple(c,x,y));
    }
    sort(edges.begin(),edges.end());
    long long ans = 0;
    for (auto it: edges)
    {
        long long cost = get<0>(it);
        int x = get<1>(it), y = get<2>(it);
        if (find(x)!=find(y))
        {
            ans+=cost;
            unite(x,y);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
int link[N],size[N];
pair<long long,int> v[N];
vector< tuple<long long,int,int> > edges;

int find(int x)
{
    while (x!=link[x])
        x = link[x];
    return x;
}
void unite(int x, int y)
{
    x = link[x];
    y = link[y];
    if (size[x]<size[y])
        swap(x,y);
    size[x]+=size[y];
    link[y] = x;
}

int main()
{
    int n,m;
    cin >> n >> m;
    for (int i = 1; i<=n; i++)
    {
        cin >> v[i].first;
        v[i].second = i;
        link[i] = i;
        size[i] = 1;
    }
    sort(v+1,v+n+1);
    for (int i = 2; i<=n; i++)
        edges.push_back(make_tuple(v[1].first+v[i].first,v[1].second,v[i].second));
    for (int i = 1; i<=m; i++)
    {
        int x,y,c;
        cin >> x >> y >> c;
        edges.push_back(make_tuple(c,x,y));
    }
    sort(edges.begin(),edges.end());
    long long ans = 0;
    for (auto it: edges)
    {
        long long cost = get<0>(it);
        int x = get<1>(it), y = get<2>(it);
        if (find(x)!=find(y))
        {
            ans+=cost;
            unite(x,y);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
int link[N],Size[N];
pair<long long,int> v[N];
vector< tuple<long long,int,int> > edges;

int find(int x)
{
    while (x!=link[x])
        x = link[x];
    return x;
}
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (Size[x]<Size[y])
        swap(x,y);
    Size[x]+=Size[y];
    link[y] = x;
}

int main()
{
    int n,m;
    cin >> n >> m;
    for (int i = 1; i<=n; i++)
    {
        cin >> v[i].first;
        v[i].second = i;
        link[i] = i;
        Size[i] = 1;
    }
    sort(v+1,v+n+1);
    for (int i = 2; i<=n; i++)
        edges.push_back(make_tuple(v[1].first+v[i].first,v[1].second,v[i].second));
    for (int i = 1; i<=m; i++)
    {
        int x,y;
        long long c;
        cin >> x >> y >> c;
        edges.push_back(make_tuple(c,x,y));
    }
    sort(edges.begin(),edges.end());
    long long ans = 0;
    for (auto it: edges)
    {
        long long cost = get<0>(it);
        int x = get<1>(it), y = get<2>(it);
        if (find(x)!=find(y))
        {
            ans+=cost;
            unite(x,y);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
int link[N],Size[N];
long long v[N];
vector< tuple<long long,int,int> > edges;

int find(int x)
{
    while (x!=link[x])
        x = link[x];
    return x;
}
void unite(int x, int y)
{
    x = link[x];
    y = link[y];
    if (Size[x]<Size[y])
        swap(x,y);
    Size[x]+=Size[y];
    link[y] = x;
}

int main()
{
    int n,m;
    cin >> n >> m;
    for (int i = 1; i<=n; i++)
    {
        cin >> v[i];
        Size[i] = 1;
        link[i] = i;
    }
    long long Min = v[1];
    int poz = 1;
    for (int i = 2; i<=n; i++)
        if (v[i]<Min)
        {
            Min = v[i];
            poz = i;
        }
    for (int i = 1; i<=n; i++)
        if (poz!=i)
            edges.push_back(make_tuple(v[i]+v[poz],i,poz));
    for (int i = 1; i<=m; i++)
    {
        int x,y;
        long long c;
        cin >> x >> y >> c;
        edges.push_back(make_tuple(c,x,y));
    }
    sort(edges.begin(),edges.end());
    long long ans = 0;
    for (auto it: edges)
    {
        long long cost = get<0>(it);
        int x = get<1>(it), y = get<2>(it);
        if (find(x)!=find(y))
        {
            ans+=cost;
            unite(x,y);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
int link[N],Size[N];
pair<long long,int> v[N];
vector< tuple<long long,int,int> > edges;

int find(int x)
{
    while (x!=link[x])
        x = link[x];
    return x;
}
void unite(int x, int y)
{
    x = link[x];
    y = link[y];
    if (Size[x]<Size[y])
        swap(x,y);
    Size[x]+=Size[y];
    link[y] = x;
}

int main()
{
    int n,m;
    cin >> n >> m;
    for (int i = 1; i<=n; i++)
    {
        cin >> v[i].first;
        v[i].second = i;
    }
    sort(v+1,v+n+1);
    for (int i = 1; i<=n; i++)
    {
        Size[i] = 1;
        link[i] = v[i].second;
    }
    for (int i = 2; i<=n; i++)
        edges.push_back(make_tuple(v[1].first+v[i].first,v[1].second,v[i].second));
    for (int i = 1; i<=m; i++)
    {
        int x,y;
        long long c;
        cin >> x >> y >> c;
        edges.push_back(make_tuple(c,x,y));
    }
    sort(edges.begin(),edges.end());
    long long ans = 0;
    for (auto it: edges)
    {
        long long cost = get<0>(it);
        int x = get<1>(it), y = get<2>(it);
        if (find(x)!=find(y))
        {
            ans+=cost;
            unite(x,y);
        }
    }
    cout << ans;
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

ll ncase = 1;
const int mxn = 2e5 + 5;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      A[b] = min(A[a], A[b]);
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      A[a] = min(A[a], A[b]);
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<int, vi, cmp> q;
  for(int i=0; i<N; ++i) q.push(i);
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top()); q.pop();
    int n2 = uf.Find(q.top()); q.pop();
    if(n1 == n2) {
      q.push(n1);
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X <= cost) {
      int n1 = uf.Find(G[n].Y.X), n2 = uf.Find(G[n].Y.Y);
      ll& cost_path = G[n].X;
      ++n;
      if(n1 == n2) continue;
      ll cost2 = A[n1] + A[n2];
      if(cost_path <= cost2) ans += cost_path, q.push(uf.Union(n1, n2));
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push(n1);
      continue;
    }
    ans += A[n1] + A[n2];
    q.push(uf.Union(n1, n2));
  }

  cout << ans << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

ll ncase = 1;
const int mxn = 2e5 + 50;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    A[a] = A[b] = min(A[a], A[b]);
    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<int, vi, cmp> q;
  for(int i=0; i<N; ++i) q.push(i);
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top()); q.pop();
    int n2 = uf.Find(q.top()); q.pop();
    if(n1 == n2) {
      q.push(n1);
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X < cost) {
      int nn1 = uf.Find(G[n].Y.X), nn2 = uf.Find(G[n].Y.Y);
      ll cost_path = G[n].X;
      ++n;
      if(nn1 == nn2) continue;
      ans += cost_path, q.push(uf.Union(nn1, nn2));
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push(n1);
      continue;
    }
    ans += A[n1] + A[n2];
    q.push(uf.Union(n1, n2));
  }

  cout << ans << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

ll ncase = 1;
const int mxn = 2e5 + 5;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      A[b] = min(A[a], A[b]);
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      A[a] = min(A[a], A[b]);
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<int, vi, cmp> q;
  for(int i=0; i<N; ++i) q.push(i);
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top()); q.pop();
    int n2 = uf.Find(q.top()); q.pop();
    if(n1 == n2) {
      q.push(n1);
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X < cost) {
      int nn1 = uf.Find(G[n].Y.X), nn2 = uf.Find(G[n].Y.Y);
      ll& cost_path = G[n].X;
      ++n;
      if(nn1 == nn2) continue;
      ll cost2 = A[nn1] + A[nn2];
      if(cost_path <= cost2) ans += cost_path, q.push(uf.Union(nn1, nn2));
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push(n1);
      continue;
    }
    ans += A[n1] + A[n2];
    q.push(uf.Union(n1, n2));
  }

  cout << ans << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

ll ncase = 1;
const int mxn = 2e5 + 5;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    A[a] = A[b] = min(A[a], A[b]);
    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      //A[a] = min(A[a], A[b]);
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<int, vi, cmp> q;
  for(int i=0; i<N; ++i) q.push(i);
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top()); q.pop();
    int n2 = uf.Find(q.top()); q.pop();
    if(n1 == n2) {
      q.push(n1);
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X < cost) {
      int nn1 = uf.Find(G[n].Y.X), nn2 = uf.Find(G[n].Y.Y);
      ll& cost_path = G[n].X;
      ++n;
      if(nn1 == nn2) continue;
      ans += cost_path, q.push(uf.Union(nn1, nn2));
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push(n1);
      continue;
    }
    ans += A[n1] + A[n2];
    q.push(uf.Union(n1, n2));
  }

  cout << ans << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

ll ncase = 1;
const int mxn = 2e5 + 5;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      A[b] = min(A[a], A[b]);
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      A[a] = min(A[a], A[b]);
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<int, vi, cmp> q;
  for(int i=0; i<N; ++i) q.push(i);
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top()); q.pop();
    int n2 = uf.Find(q.top()); q.pop();
    if(n1 == n2) {
      q.push(n1);
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X <= cost) {
      int n1 = uf.Find(G[n].Y.X), n2 = uf.Find(G[n].Y.Y);
      ll& cost_path = G[n].X;
      ++n;
      if(n1 == n2) continue;
      ll cost2 = A[n1] + A[n2];
      if(cost_path <= cost2) ans += cost_path, uf.Union(n1, n2);
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push(n1);
      continue;
    }
    ans += A[n1] + A[n2];
    q.push(uf.Union(n1, n2));
  }

  cout << ans << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

ll ncase = 1;
const int mxn = 2e5 + 50;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    A[a] = A[b] = min(A[a], A[b]);
    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<int, vi, cmp> q;
  for(int i=0; i<N; ++i) q.push(i);
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top()); q.pop();
    int n2 = uf.Find(q.top()); q.pop();
    if(n1 == n2) {
      q.push(n1);
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X < cost) {
      int nn1 = uf.Find(G[n].Y.X), nn2 = uf.Find(G[n].Y.Y);
      ll& cost_path = G[n].X;
      ++n;
      if(nn1 == nn2) continue;
      ans += cost_path, q.push(uf.Union(nn1, nn2));
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push(n1);
      continue;
    }
    ans += A[n1] + A[n2];
    q.push(uf.Union(n1, n2));
  }

  cout << ans << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

ll ncase = 1;
const int mxn = 2e5 + 50;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    A[a] = A[b] = min(A[a], A[b]);
    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<int, vi, cmp> q;
  for(int i=0; i<N; ++i) q.push(i);
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top()); q.pop();
    int n2 = uf.Find(q.top()); q.pop();
    if(n1 == n2) {
      q.push(n1);
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X < cost) {   // 如果 special offer 較好
      int nn1 = uf.Find(G[n].Y.X), nn2 = uf.Find(G[n].Y.Y);
      ll cost_path = G[n].X;
      ++n;
      if(nn1 == nn2) continue;
      A[nn1] = B[nn2] = min(A[nn1], B[nn2]);
      ans += cost_path, q.push(uf.Union(nn1, nn2));
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push(n1);
      continue;
    }
    ans += A[n1] + A[n2];
    q.push(uf.Union(n1, n2));
  }

  cout << ans << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

ll ncase = 1;
const int mxn = 2e5 + 50;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    A[a] = A[b] = min(A[a], A[b]);
    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<int, vi, cmp> q;
  for(int i=0; i<N; ++i) q.push(i);
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top()); q.pop();
    int n2 = uf.Find(q.top()); q.pop();
    if(n1 == n2) {
      q.push(n1);
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X < cost) {   // 如果 special offer 較好
      int nn1 = uf.Find(G[n].Y.X), nn2 = uf.Find(G[n].Y.Y);
      ll cost_path = G[n].X;
      ++n;
      if(nn1 == nn2) continue;
      A[nn1] = A[nn2] = min(A[nn1], A[nn2]);
      ans += cost_path, q.push(uf.Union(nn1, nn2));
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push(n1);
      continue;
    }
    ans += A[n1] + A[n2];
    q.push(uf.Union(n1, n2));
  }

  cout << ans << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

ll ncase = 1;
const int mxn = 2e5 + 50;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    A[a] = A[b] = min(A[a], A[b]);
    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  int cnt = 0;
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<int, vi, cmp> q;
  for(int i=0; i<N; ++i) q.push(i);
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top()); q.pop();
    int n2 = uf.Find(q.top()); q.pop();
    if(n1 == n2) {
      q.push(n1);
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X < cost) {
      int nn1 = uf.Find(G[n].Y.X), nn2 = uf.Find(G[n].Y.Y);
      ll cost_path = G[n].X;
      ++n;
      if(nn1 == nn2) continue;
      ans += cost_path, q.push(uf.Union(nn1, nn2));
      ++cnt;
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push(n1);
      continue;
    }
    ans += A[n1] + A[n2];
    ++cnt;
    q.push(uf.Union(n1, n2));
  }

  cout << ans << endl;
  if(N == 200000 && M == 100000)
    cout << cnt << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

ll ncase = 1;
const int mxn = 2e5 + 5;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    A[a] = A[b] = min(A[a], A[b]);
    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      //A[a] = min(A[a], A[b]);
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<int, vi, cmp> q;
  for(int i=0; i<N; ++i) q.push(i);
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top()); q.pop();
    int n2 = uf.Find(q.top()); q.pop();
    if(n1 == n2) {
      q.push(n1);
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X < cost) {
      int nn1 = uf.Find(G[n].Y.X), nn2 = uf.Find(G[n].Y.Y);
      ll& cost_path = G[n].X;
      ++n;
      if(nn1 == nn2) continue;
      ll cost2 = A[nn1] + A[nn2];
      if(cost_path <= cost2) ans += cost_path, q.push(uf.Union(nn1, nn2));
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push(n1);
      continue;
    }
    ans += A[n1] + A[n2];
    q.push(uf.Union(n1, n2));
  }

  cout << ans << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

typedef pair<ll, int> li;
ll ncase = 1;
const int mxn = 2e5 + 50;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    A[a] = A[b] = min(A[a], A[b]);
    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<li, vector<li>, greater<li>> q;
  for(int i=0; i<N; ++i) q.push({A[i],i});
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top().Y); q.pop();
    int n2 = uf.Find(q.top().Y); q.pop();
    if(n1 == n2) {
      q.push({A[n1], n1});
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X < cost) {   // 如果 special offer 較好
      int nn1 = uf.Find(G[n].Y.X), nn2 = uf.Find(G[n].Y.Y);
      ll cost_path = G[n].X;
      ++n;
      if(nn1 == nn2) continue;
      int id = uf.Union(nn1, nn2);
      ans += cost_path, q.push({A[id], id});
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push({A[n1], n1});
      continue;
    }
    ans += A[n1] + A[n2];
    int id = uf.Union(n1, n2);
    q.push({A[id], id});
  }

  cout << ans << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


//hi~ :)
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline ll gi(){   // getint()
  ll _x=0,_tmp=1; char _tc=getchar();
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
////////////////////////////////////////////

ll ncase = 1;
const int mxn = 2e5 + 5;
ll N,M;
ll A[mxn];
pair<ll, ii> G[mxn];

struct UF {
  std::vector<int> par, hei, sz;
  UF(const int& sz_) : par(sz_), hei(sz_, 0), sz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i] = i;
  }
  void Init(const int& sz_) {
    par.resize(sz_);
    hei.resize(sz_);
    sz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, hei[i] = 0, sz[i] = 1;
  }
  int Find(const int& n) {
    if(par[n] == n) return n;
    return par[n] = Find(par[n]);
  }
  int Union(int a, int b) {
    a = Find(a), b = Find(b);
    if(a == b) return a;
    if(hei[a] == hei[b]) ++hei[a];

    if(hei[a] < hei[b]) {
      par[a] = b, sz[b] += sz[a];
      A[b] = min(A[a], A[b]);
      return b;
    }
    else {
      par[b] = a, sz[a] += sz[b];
      A[a] = min(A[a], A[b]);
      return a;
    }
  }
  int Size(const int& n) {
    return sz[Find(n)];
  }
};
// UF uf(10000);
// uf. Find(1); Union(1, 100); Size(1); Init(50); 0-base

void pre(){
  return;
}
void init(){
  int a, b;
  ll c;
  N = gi(), M = gi();
  for(int i=0; i<N; ++i) A[i] = gi();
  for(int i=0; i<M; ++i) {
    a = gi()-1, b = gi()-1, c = gi();
    G[i] = {c, {a, b}};
  }
}
struct cmp {
  bool operator() (int a, int b) const {
    return A[a] > A[b];
  }
};
void sol(){
  UF uf(N);
  sort(G, G+M);
  int n = 0;
  priority_queue<int, vi, cmp> q;
  for(int i=0; i<N; ++i) q.push(i);
  ll ans = 0;
  while(q.size()>1) {
    int n1 = uf.Find(q.top()); q.pop();
    int n2 = uf.Find(q.top()); q.pop();
    if(n1 == n2) {
      q.push(n1);
      continue;
    }
    ll cost = A[n1] + A[n2];
    while(n < M && G[n].X < cost) {
      int n1 = uf.Find(G[n].Y.X), n2 = uf.Find(G[n].Y.Y);
      ll& cost_path = G[n].X;
      ++n;
      if(n1 == n2) continue;
      ll cost2 = A[n1] + A[n2];
      if(cost_path <= cost2) ans += cost_path, q.push(uf.Union(n1, n2));
    }
    if((n1 = uf.Find(n1)) == (n2 = uf.Find(n2))) {
      q.push(n1);
      continue;
    }
    ans += A[n1] + A[n2];
    q.push(uf.Union(n1, n2));
  }

  cout << ans << endl;

  return ;
}

int main(){
  pre();
  //ncase = getint();
  while( ncase -- ){
    init();
    sol();
  }
}


#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define err1(a) cout<<a<<endl
#define err2(a,b) cout<<a<<" "<<b<<endl
#define err3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define mp make_pair
#define pb push_back
#define alll(it,A) for(it=A.begin();it!=A.end();it++)
#define ft first
#define sd second
#define pll pair<ll,ll>
#define N 200005
#define V vector<ll>
#define S set<ll>

ll A[N];
bool vis[N];
vector<pair<pll,ll>> v;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll mi=1e13,flag;
    rep(i,1,n+1){
    	cin>>A[i];
    	if(A[i]<mi)	mi=A[i],flag=i;
    }
    memset(vis,0,sizeof(vis));
    vis[flag]=1;
    ll ans=0;
    rep(i,0,m){
    	ll l,r,x;
    	cin>>l>>r>>x;
    	v.pb(mp(mp(l,r),x));
    	v.pb(mp(mp(r,l),x));
    }
    sort(v.begin(),v.end());
    ll cnt=0,j=0;
    rep(i,1,n+1){
    	if(i!=flag){
        	cnt=mi+A[i];
            while(j<m && v[j].ft.ft==i){
            	cnt=min(cnt,v[j].sd);
            	j++;
        	}
        	ans+=cnt;
        }
        else{
            while(j<m && v[j].ft.ft==i)    j++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define err1(a) cout<<a<<endl
#define err2(a,b) cout<<a<<" "<<b<<endl
#define err3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define mp make_pair
#define pb push_back
#define alll(it,A) for(it=A.begin();it!=A.end();it++)
#define ft first
#define sd second
#define pll pair<ll,ll>
#define N 200005
#define V vector<ll>
#define S set<ll>

ll A[N];
bool vis[N];
map<pll,ll> v;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll mi=1e13+2,flag;
    rep(i,1,n+1){
    	cin>>A[i];
    	if(A[i]<mi)	mi=A[i],flag=i;
    }
    memset(vis,0,sizeof(vis));
    vis[flag]=1;
    ll ans=0;
    rep(i,0,m){
    	ll l,r,x;
    	cin>>l>>r>>x;
    	v.insert(mp(mp(l,r),x));
    	v.insert(mp(mp(r,l),x));
    }
    ll cnt=0,j=0;
    map<pll,ll> ::  iterator it=v.begin();
    rep(i,1,n+1){
    	if(i!=flag){
        	cnt=mi+A[i];
            bool f=0;
            map<pll,ll> ::  iterator it1=it;
            while(it!=v.end() && it->ft.ft==i){
            	if(cnt>(it->sd)) f=1,cnt=it->sd;
            	it++;
        	}
            if(f){
                while(it1->sd!=cnt) it1++;
                v.erase(v.find(mp(it1->ft.ft,it1->ft.sd)));
                v.erase(v.find(mp(it1->ft.sd,it1->ft.ft)));
            }
            err2(i,cnt);
        	ans+=cnt;
        }
        else{
            while(it!=v.end() && it->ft.ft==i)    it++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define err1(a) cout<<a<<endl
#define err2(a,b) cout<<a<<" "<<b<<endl
#define err3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define alll(it,A) for(it=A.begin();it!=A.end();it++)
#define ft first
#define sd second
#define pll pair<ll,ll>
#define N 300005
#define V vector<ll>
#define S set<ll>

ll B[N],A[N];
vector<pair<ll,pll>> v;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll flag,min=1e13;
    rep(i,1,n+1){
        cin>>A[i];
        if(A[i]<min)    min=A[i],flag=i;
    }
    rep(i,0,m){
        ll l,r,d;
        cin>>l>>r>>d;
        v.pb(mp(d,mp(l,r)));
    }
    rep(i,1,n+1){
        if(i!=flag){
            v.pb(mp(A[i]+min,mp(i,flag)));
        }
        B[i]=i;
    }
    sort(all(v));
    ll cnt=0,ans=0;
    vector<pair<ll,pll>> :: iterator i;
    alll(i,v){
        ll x=i->sd.ft,y=i->sd.sd;
        while(B[x]!=x) x=B[x];
        while(B[y]!=y) y=B[y];
        if(x!=y){
            B[x]=y;
            ans+=(i->ft);
            cnt++;
        }
        if(cnt==n-1){
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define err1(a) cout<<a<<endl
#define err2(a,b) cout<<a<<" "<<b<<endl
#define err3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define alll(it,A) for(it=A.begin();it!=A.end();it++)
#define ft first
#define sd second
#define pll pair<ll,ll>
#define N 300005
#define V vector<ll>
#define S set<ll>

ll B[N],A[N];
vector<pair<ll,pll>> v;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll flag,min=1e13;
    rep(i,1,n+1){
        cin>>A[i];
        if(A[i]<min)    min=A[i],flag=i;
    }
    rep(i,0,m){
        ll l,r,d;
        cin>>l>>r>>d;
        v.pb(mp(d,mp(l,r)));
    }
    rep(i,1,n+1){
        if(i!=flag){
            v.pb(mp(A[i]+min,mp(i,flag)));
        }
        B[i]=i;
    }
    sort(all(v));
    ll cnt=0,ans=0;
    for(auto i : v){
        ll x=i.sd.ft,y=i.sd.sd;
        while(B[x]!=x) x=B[x];
        while(B[y]!=y) y=B[y];
        if(x!=y){
            B[x]=y;
            ans+=i.ft;
            cnt++;
        }
        if(cnt>=n-1){
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define err1(a) cout<<a<<endl
#define err2(a,b) cout<<a<<" "<<b<<endl
#define err3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define alll(it,A) for(it=A.begin();it!=A.end();it++)
#define ft first
#define sd second
#define pll pair<ll,ll>
#define N 300005
#define V vector<ll>
#define S set<ll>

ll B[N],A[N];
vector<pair<ll,pll>> v;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll flag,min=1e13;
    rep(i,1,n+1){
        cin>>A[i];
        if(A[i]<min)    min=A[i],flag=i;
    }
    rep(i,0,m){
        ll l,r,d;
        cin>>l>>r>>d;
        v.pb(mp(d,mp(l,r)));
    }
    rep(i,1,n+1){
        if(i!=flag){
            v.pb(mp(A[i]+min,mp(i,flag)));
        }
        B[i]=i;
    }
    sort(all(v));
    ll cnt=0,ans=0;
    vector<pair<ll,pll>> :: iterator i;
    alll(i,v){
        ll x=i->sd.ft,y=i->sd.sd;
        ll a=0,b=0;
        while(B[x]!=x) a++,x=B[x];
        while(B[y]!=y) b++,y=B[y];
        if(x!=y){
            if(a>b) B[y]=x;
            else B[x]=y;
            ans+=(i->ft);
            cnt++;
        }
        if(cnt==n-1){
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define err1(a) cout<<a<<endl
#define err2(a,b) cout<<a<<" "<<b<<endl
#define err3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define mp make_pair
#define pb push_back
#define alll(it,A) for(it=A.begin();it!=A.end();it++)
#define ft first
#define sd second
#define pll pair<ll,ll>
#define N 200005
#define V vector<ll>
#define S set<ll>

ll A[N];
bool vis[N];
map<pll,ll> v;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll mi=1e13+2,flag;
    rep(i,1,n+1){
    	cin>>A[i];
    	if(A[i]<mi)	mi=A[i],flag=i;
    }
    memset(vis,0,sizeof(vis));
    vis[flag]=1;
    ll ans=0;
    rep(i,0,m){
    	ll l,r,x;
    	cin>>l>>r>>x;
    	v.insert(mp(mp(l,r),x));
    	v.insert(mp(mp(r,l),x));
    }
    ll cnt=0,j=0;
    map<pll,ll> ::  iterator it=v.begin();
    rep(i,1,n+1){
    	if(i!=flag){
        	cnt=mi+A[i];
            bool f=0;
            map<pll,ll> ::  iterator it1=it;
            while(it!=v.end() && it->ft.ft==i){
            	if(cnt>(it->sd)) f=1,cnt=it->sd;
            	it++;
        	}
            if(f){
                while(it1->sd!=cnt) it1++;
                v.erase(v.find(mp(it1->ft.ft,it1->ft.sd)));
                v.erase(v.find(mp(it1->ft.sd,it1->ft.ft)));
            }
            //err2(i,cnt);
        	ans+=cnt;
        }
        else{
            while(it!=v.end() && it->ft.ft==i)    it++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define err1(a) cout<<a<<endl
#define err2(a,b) cout<<a<<" "<<b<<endl
#define err3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define alll(it,A) for(it=A.begin();it!=A.end();it++)
#define ft first
#define sd second
#define pll pair<ll,ll>
#define N 200005
#define V vector<ll>
#define S set<ll>

ll B[N],A[N];
vector<pair<ll,pll>> v;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll flag,min=1e13;
    rep(i,1,n+1){
        cin>>A[i];
        if(A[i]<min)    min=A[i],flag=i;
    }
    rep(i,0,m){
        ll l,r,d;
        cin>>l>>r>>d;
        v.pb(mp(d,mp(l,r)));
    }
    rep(i,1,n+1){
        if(i!=flag){
            v.pb(mp(A[i]+min,mp(i,flag)));
        }
    }
    sort(all(v));
    ll cnt=0,ans=0;
    memset(B,-1,sizeof(B));
    for(auto i : v){
        ll x=i.sd.ft,y=i.sd.sd;
        while(B[x]!=-1) x=B[x];
        while(B[y]!=-1) y=B[y];
        if(x!=y){
            B[x]=y;
            ans+=i.ft;
            cnt++;
        }
        //err2(i.ft,cnt);
        if(cnt>=n-1){
            break;
        }

    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <random>

using namespace std;

typedef long long ll;

struct Edge {
    int from;
    int to;
    ll weight;
};

bool cmp( const Edge& fst, const Edge& snd ) {
    return fst.weight < snd.weight;
}

int find( int x, vector<int>& p ) {
    if( p[x] == x ) {
        return x;
    }
    int root = find( p[x], p );
    p[x] = root;
    return root;
}

bool add( int from, int to, vector<int>& p ) {
    int fst = find( from, p );
    int snd = find( to, p );
    if( fst == snd ) {
        return false;
    }
    if( rand() % 2 == 0 ) {
        p[fst] = snd;
    } else {
        p[snd] = fst;
    }

    return true;
}

int main() {
    ios_base::sync_with_stdio( false );
    cin.tie( nullptr );
    cout.tie( nullptr );

    int n, m;
    cin >> n >> m;

    vector<pair<ll, int>> a( n );
    for( int i = 0; i < n; ++i ) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort( a.begin(), a.end() );

    vector<int> p( n );
    for( int i = 0; i < n; ++i ) {
        p[i] = i;
    }

    vector<Edge> edges( m );
    for( auto& x : edges ) {
        cin >> x.from >> x.to >> x.weight;
        --x.from; --x.to;
    }
    sort( edges.begin(), edges.end(), cmp );

    ll ans = 0;
    int ind = 1;
    int indE = 0;
    int cnt = 0;
    while( cnt < n - 1 ) {
        bool added;
        if( indE != edges.size() || a[0].first + a[ind].first < edges[indE].weight ) {
            added = add( a[0].second, a[ind].second, p );
            if( added ) {
                ans += a[0].first + a[ind].first;
                ++cnt;
            }
            ++ind;
        } else {
            added = add( edges[indE].from, edges[indE].to, p );
            if( added ) {
                ans += edges[indE].weight;
                ++cnt;
            }
            ++indE;
        }
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

typedef long long ll;

struct Edge {
    int from;
    int to;
    ll weight;
};

bool cmp( const Edge& fst, const Edge& snd ) {
    return fst.weight < snd.weight;
}

int find( int x, vector<int>& p ) {
    if( p[x] == x ) {
        return x;
    }
    int root = find( p[x], p );
    p[x] = root;
    return root;
}

bool add( int from, int to, vector<int>& p ) {
    int fst = find( from, p );
    int snd = find( to, p );
    if( fst == snd ) {
        return false;
    }
    p[fst] = snd;
    return true;
}

int main() {
    ios_base::sync_with_stdio( false );
    cin.tie( nullptr );
    cout.tie( nullptr );

    int n, m;
    cin >> n >> m;

    vector<int> a( n );
    for( auto& x : a ) {
        cin >> x;
    }
    vector<int> p( n );
    for( int i = 0; i < n; ++i ) {
        p[i] = i;
    }

    vector<Edge> edges( m );
    for( auto& x : edges ) {
        cin >> x.from >> x.to >> x.weight;
        --x.from; --x.to;
    }
    sort( edges.begin(), edges.end(), cmp );

    ll ans = 0;
    int ind = 1;
    int cnt = 0;
    while( cnt < n - 1 ) {
        bool added;
        if( edges.empty() || a[0] + a[ind] < edges.begin()->weight ) {
            added = add( 0, ind, p );
            if( added ) {
                ans += a[0] + a[ind];
                ++cnt;
            }
            ++ind;
        } else {
            added = add( edges.begin()->from, edges.begin()->to, p );
            if( added ) {
                ans += edges.begin()->weight;
                ++cnt;
            }
            edges.erase( edges.begin() );
        }
    }

    cout << ans << endl;

    return 0;
}