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

using namespace std;

auto main() -> int
{
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    vector<int> B(m);
    for(int i = 0; i < n; i++)
        cin >> A[i];
    for(int i = 0; i < m; i++)
        cin >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if(2 * A[0] > A[n - 1] || A[n - 1] >= B[0]) {
        if(A[0] == A[n - 1] && 2 * A[0] < B[0]) {
            cout << 2 * A[0] << endl;
            return 0;
        }
        cout << -1 << endl;
        return 0;
    }
    cout << A[n - 1] << endl;

    return 0;
}


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

using namespace std;

auto main() -> int
{
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    vector<int> B(m);
    for(int i = 0; i < n; i++)
        cin >> A[i];
    for(int i = 0; i < m; i++)
        cin >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if(2 * A[0] > A[n - 1] || A[n - 1] >= B[0]) {
        if(n == 1 && 2 * A[0] < B[0]) {
            cout << 2 * A[0] << endl;
            return 0;
        }
        cout << -1 << endl;
        return 0;
    }
    cout << A[n - 1] << endl;

    return 0;
}


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

using namespace std;

auto main() -> int
{
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    vector<int> B(m);
    for(int i = 0; i < n; i++)
        cin >> A[i];
    for(int i = 0; i < m; i++)
        cin >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if(2 * A[0] > A[n - 1] || A[n - 1] >= B[0]) {
        cout << -1 << endl;
        return 0;
    }
    cout << A[n - 1] << endl;

    return 0;
}


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

using namespace std;

auto main() -> int
{
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    vector<int> B(m);
    for(int i = 0; i < n; i++) cin >> A[i];
    for(int i = 0; i < m; i++) cin >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if(2 * A[0] > A[n - 1] || A[n - 1] >= B[0]) {
        if(((A[0] == A[n - 1]) || (2 * A[0] > A[n - 1])) && 2 * A[0] < B[0]) {
            cout << 2 * A[0] << endl;
            return 0;
        }
        cout << -1 << endl;
        return 0;
    }
    cout << A[n - 1] << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int x,y;
int mn=INT_MAX,mx=INT_MIN;
for(int i=0;i<n;i++){
    cin>>x;
    mx=max(x,mx);
    mn=min(x,mn);
}
int tl=max(mx,2*mn);
bool f=0;
for(int i=0;i<m;i++){
    cin>>x;
    if(x<=tl)f=1;
}
if(f)cout<<-1<<endl;
else cout<<tl<<endl;
return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define sqr(x) ((x)*(x))
#define fi first
#define se second
#define pb push_back
#define pp pop_back
#define sz(x) int( (x).size() )
#define inf int(~0U>>1)
#define INF ll(~0ULL>>1)
#define p(i) (1LL<<((i)-1))
#define w(x,i) ((x)&p(i))
#define rep(i,s,t) for (i=(s); i<=(t); ++i)
#define dep(i,t,s) for (i=(t); i>=(s); --i)
#define each(i,x) for (auto i=(x).begin(); i!=(x).end(); ++i)
#define dach(i,x) for (auto i=(x).rbegin(); i!=(x).rend(); ++i)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;

typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;

template<class T> inline T nx(T x) { return ++x; }
template<class T> inline T pr(T x) { return --x; }

template<class T>
inline void get(T &n) {
	char c = getchar();
	while (c!='-' && (c<'0' || c>'9')) c = getchar();
	n = 0; T s = 1; if (c=='-') s = -1,c = getchar();
	while (c>='0' && c<='9') n*=10,n+=c-'0',c=getchar();
	n *= s;
}

const int maxn = 110;
int a[maxn],b[maxn],n,m;

int main() {
    int i,j,k,t,tt;
	get(n); get(m);
	rep(i,1,n) get(a[i]);
	rep(i,1,m) get(b[i]);
	sort(a+1,a+n+1); sort(b+1,b+m+1);
	int v = -1;
	rep(t,a[n],b[1]-1) {
		if (a[1]*2 <= t) { v = t; break; }
	}
	if (v>=0) printf("%d\n",v);
	else puts("-1");

    return 0;
}


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>

using namespace std;
int n,m;
int a[10001];
int b[10001];
int main(){
    cin>>n;
    cin>>m;
    for(int i=0; i<n; i++){
     cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0; i<m; i++){
        cin>>b[i];
    }
    sort(b,b+m);

    if(b[0] <= a[n-1]){

        cout<<-1<<endl;return 0;
    }

    for(int i=a[n-1]; i<b[0]; i++){
        if(a[0]*2 <= i){
            cout<<i<<endl;
            return 0;
        }

    }

    cout<<-1<<endl;
    return 0;
}
/*
3 6
4 5 2
8 9 6 10 7 11
3 1
3 4 5
6
*/


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>

using namespace std;
int n,m;
int a[10001];
int b[10001];
int main(){
    cin>>n;
    cin>>m;
    for(int i=0; i<n; i++){
     cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0; i<m; i++){
        cin>>b[i];
    }
    sort(b,b+n);
    if(b[0] <= a[n-1]){
        cout<<-1<<endl;return 0;
    }

    for(int i=a[n-1]; i<b[0]; i++){
        if(a[0]*2 <= i){
            cout<<i<<endl;
            return 0;
        }

    }

    cout<<-1<<endl;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>

using namespace std;
int n,m;
int a[10001];
int b[10001];
int main(){
    cin>>n;
    cin>>m;
    for(int i=0; i<n; i++){
     cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0; i<m; i++){
        cin>>b[i];
    }
    sort(b,b+m);

    if(b[0] <= a[n-1]){
            cout<<b[0]<<a[n-1]<<endl;
        cout<<-1<<endl;return 0;
    }

    for(int i=a[n-1]; i<b[0]; i++){
        if(a[0]*2 <= i){
            cout<<i<<endl;
            return 0;
        }

    }

    cout<<-1<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/algorithm>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#ifdef HOME
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl;
#else
#define DB(x)
#endif

#define all(c) (c).begin(),(c).end()
#define mp make_pair

const int oo = 0x3f3f3f3f;

typedef long long i64;
typedef pair<int,int> pii;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

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

    vector<int> a(n), b(m);

    for(auto &i : a) cin >> i;
    for(auto &i : b) cin >> i;

    sort(all(a));
    sort(all(b));

    int t = max(2*a.front(),a.back());

    if(t >= b[0]) cout << -1 << endl;
    else cout << t << endl;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<utility>
#include<set>
#include<vector>
#include<stdio.h>
using namespace std;

int main()
{
int n,m;
scanf("%d %d",&n,&m);
int a[n],b[m],c[n];
for(int i=0;i<n;i++)
{
    scanf("%d",&a[i]);
    c[i]=2*a[i];
}
for(int i=0;i<m;i++)
{
    scanf("%d",&b[i]);

}
sort(&a[0],&a[n]);
sort(&b[0],&b[m]);
int min=a[0],max=a[n-1];
int v;
if(2*min >= max)
{
 v=2*min;
}else
 v=max;
if(v < b[0])
    printf("%d\n",v);
else printf("-1\n");
return 0;}


#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<utility>
#include<set>
#include<vector>
#include<stdio.h>
using namespace std;

int checkatleast(int c[],int n,int v)
{
   for(int i=0;i<n;i++)
   {
       if(c[i]<=v)
        return 1;
   }
  return 0;
}

int main()
{
int n,m;
scanf("%d %d",&n,&m);
int a[n],b[m],c[n];
for(int i=0;i<n;i++)
{
    scanf("%d",&a[i]);
    c[i]=2*a[i];
}
for(int i=0;i<m;i++)
{
    scanf("%d",&b[i]);

}
sort(&a[0],&a[n]);
sort(&b[0],&b[m]);
int v=a[n-1];
if(checkatleast(c,n,v) && v < b[0])
    printf("%d\n",v);
else printf("-1\n");
return 0;}


#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)

#define DEBUG(x) { cout << #x << " = "; cout << x << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
using namespace std;

//Buffer reading
int INP,AM,REACHEOF;
const int BUFSIZE = (1<<12) + 17;
char BUF[BUFSIZE+1], *inp=BUF;
#define GETCHAR(INP) { \
    if(!*inp && !REACHEOF) { \
        memset(BUF,0,sizeof BUF);\
        int inpzzz = fread(BUF,1,BUFSIZE,stdin);\
        if (inpzzz != BUFSIZE) REACHEOF = true;\
        inp=BUF; \
    } \
    INP=*inp++; \
}
#define DIG(a) (((a)>='0')&&((a)<='9'))
#define GN(j) { \
    AM=0;\
    GETCHAR(INP); while(!DIG(INP) && INP!='-') GETCHAR(INP);\
    if (INP=='-') {AM=1;GETCHAR(INP);} \
    j=INP-'0'; GETCHAR(INP); \
    while(DIG(INP)){j=10*j+(INP-'0');GETCHAR(INP);} \
    if (AM) j=-j;\
}
//End of buffer reading

int a[111], b[111];

int main() {
    int n, m;
    while (cin >> n >> m) {
        FOR(i,1,n) cin >> a[i];
        FOR(i,1,m) cin >> b[i];

        int tl = max(*min_element(a+1, a+n+1) * 2, *max_element(a+1, a+n+1));
        if (tl < *min_element(b+1, b+m+1)) cout << tl << endl;
        else cout << -1 << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>

using namespace std;
int max_number(vector<int>::iterator vec_begin, vector<int>::iterator vec_end)
{
	int max_num = *vec_begin;
	for(auto i = vec_begin; i != vec_end; ++i)
		if(max_num < *i )
			max_num = *i;
	return max_num;
}
int min_number(vector<int>::iterator vec_begin, vector<int>::iterator vec_end)
{
	int min_num = *vec_begin;
	for(auto i = vec_begin; i != vec_end; ++i)
		if(min_num > *i )
			min_num = *i;
	return min_num;
}
int main()
{
	vector<int> temp_n;
	vector<int> temp_m;
	int n = -1;
	int m = -1;
	while(cin >> n >> m)
	{
		if(n > 0 && m > 0){
			int temp;
			while(n-- && cin >> temp)
			{
				temp_n.push_back(temp);
			}
			while(m-- && cin >> temp)
			{
				temp_m.push_back(temp);
			}
		}
		int max_n = max_number(temp_n.begin(), temp_n.end());
		int min_n = min_number(temp_n.begin(), temp_n.end());
		int min_m = min_number(temp_m.begin(), temp_m.end());
		// ��������֪Ҫ����ȷ������������ʱ��ҪС�ڴ��������С����ʱ�䣬��Ҫʱ�������ܹ���������ʹһ����ȷ����ʱ���������
		if(max_n - min_m > 0 || 2*min_n > min_m-1)
			cout << -1 << endl;
		else
			cout << max_n << endl;
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>

using namespace std;
int max_number(vector<int>::iterator vec_begin, vector<int>::iterator vec_end)
{
	int max_num = *vec_begin;
	for(auto i = vec_begin; i != vec_end; ++i)
		if(max_num < *i )
			max_num = *i;
	return max_num;
}
int min_number(vector<int>::iterator vec_begin, vector<int>::iterator vec_end)
{
	int min_num = *vec_begin;
	for(auto i = vec_begin; i != vec_end; ++i)
		if(min_num > *i )
			min_num = *i;
	return min_num;
}
int main()
{
	vector<int> temp_n;
	vector<int> temp_m;
	int n = -1;
	int m = -1;
	while(cin >> n >> m)
	{
		if(n > 0 && m > 0){
			int temp;
			while(n-- && cin >> temp)
			{
				temp_n.push_back(temp);
			}
			while(m-- && cin >> temp)
			{
				temp_m.push_back(temp);
			}
		}
		int max_n = max_number(temp_n.begin(), temp_n.end());
		int min_n = min_number(temp_n.begin(), temp_n.end());
		int min_m = min_number(temp_m.begin(), temp_m.end());
		// ��������֪Ҫ����ȷ������������ʱ��ҪС�ڴ��������С����ʱ�䣬��Ҫʱ�������ܹ���������ʹһ����ȷ����ʱ���������
		if(max_n > min_m)
			cout << -1 << endl;
		else if(2*min_n > min_m-1)
			cout << -1 << endl;
		else{
			cout << ((max_n > 2*min_n) ? max_n : 2*min_n) << endl;
		}
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>

using namespace std;
int max_number(vector<int>::iterator vec_begin, vector<int>::iterator vec_end)
{
	int max_num = *vec_begin;
	for(auto i = vec_begin; i != vec_end; ++i)
		if(max_num < *i )
			max_num = *i;
	return max_num;
}
int min_number(vector<int>::iterator vec_begin, vector<int>::iterator vec_end)
{
	int min_num = *vec_begin;
	for(auto i = vec_begin; i != vec_end; ++i)
		if(min_num > *i )
			min_num = *i;
	return min_num;
}
int main()
{
	vector<int> temp_n;
	vector<int> temp_m;
	int n = -1;
	int m = -1;
	while(cin >> n >> m)
	{
		if(n > 0 && m > 0){
			int temp;
			while(n-- && cin >> temp)
			{
				temp_n.push_back(temp);
			}
			while(m-- && cin >> temp)
			{
				temp_m.push_back(temp);
			}
		}
		int max_n = max_number(temp_n.begin(), temp_n.end());
		int min_n = min_number(temp_n.begin(), temp_n.end());
		int min_m = min_number(temp_m.begin(), temp_m.end());
		// ��������֪Ҫ����ȷ������������ʱ��ҪС�ڴ��������С����ʱ�䣬��Ҫʱ�������ܹ���������ʹһ����ȷ����ʱ���������
		if(max_n >= min_m)
			cout << -1 << endl;
		else if(2*min_n >= min_m)
			cout << -1 << endl;
		else{
			cout << ((max_n > 2*min_n) ? max_n : 2*min_n) << endl;
		}
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>

using namespace std;
int max_number(vector<int>::iterator vec_begin, vector<int>::iterator vec_end)
{
	int max_num = *vec_begin;
	for(auto i = vec_begin; i != vec_end; ++i)
		if(max_num < *i )
			max_num = *i;
	return max_num;
}
int min_number(vector<int>::iterator vec_begin, vector<int>::iterator vec_end)
{
	int min_num = *vec_begin;
	for(auto i = vec_begin; i != vec_end; ++i)
		if(min_num > *i )
			min_num = *i;
	return min_num;
}
int main()
{
	vector<int> temp_n;
	vector<int> temp_m;
	int n = -1;
	int m = -1;
	while(cin >> n >> m)
	{
		if(n > 0 && m > 0){
			int temp;
			while(n-- && cin >> temp)
			{
				temp_n.push_back(temp);
			}
			while(m-- && cin >> temp)
			{
				temp_m.push_back(temp);
			}
		}
		int max_n = max_number(temp_n.begin(), temp_n.end());
		int min_n = min_number(temp_n.begin(), temp_n.end());
		int min_m = min_number(temp_m.begin(), temp_m.end());
		// ��������֪Ҫ����ȷ������������ʱ��ҪС�ڴ��������С����ʱ�䣬��Ҫʱ�������ܹ���������ʹһ����ȷ����ʱ���������
		if(max_n > min_m)
			cout << -1 << endl;
		else if(2*min_n > min_m-1)
			cout << -1 << endl;
		else{
			if(temp_n.size() == 1)
				cout << 2*max_n << endl;
			else{
				cout << (max_n) << endl;
			}
		}
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>

using namespace std;
int max_number(vector<int>::iterator vec_begin, vector<int>::iterator vec_end)
{
	int max_num = *vec_begin;
	for(auto i = vec_begin; i != vec_end; ++i)
		if(max_num < *i )
			max_num = *i;
	return max_num;
}
int min_number(vector<int>::iterator vec_begin, vector<int>::iterator vec_end)
{
	int min_num = *vec_begin;
	for(auto i = vec_begin; i != vec_end; ++i)
		if(min_num > *i )
			min_num = *i;
	return min_num;
}
int main()
{
	vector<int> temp_n;
	vector<int> temp_m;
	int n = -1;
	int m = -1;
	while(cin >> n >> m)
	{
		if(n > 0 && m > 0){
			int temp;
			while(n-- && cin >> temp)
			{
				temp_n.push_back(temp);
			}
			while(m-- && cin >> temp)
			{
				temp_m.push_back(temp);
			}
		}
		int max_n = max_number(temp_n.begin(), temp_n.end());
		int min_n = min_number(temp_n.begin(), temp_n.end());
		int min_m = min_number(temp_m.begin(), temp_m.end());
		// ��������֪Ҫ����ȷ������������ʱ��ҪС�ڴ��������С����ʱ�䣬��Ҫʱ�������ܹ���������ʹһ����ȷ����ʱ���������
		if(max_n > min_m)
			cout << -1 << endl;
		else if(2*min_n > min_m-1)
			cout << -1 << endl;
		else{
			if(max_n == min_n)
				cout << 2*max_n << endl;
			else{
				cout << (max_n) << endl;
			}
		}
	}

	return 0;
}


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

#define forn(i,a,b) for(int i=(a);i<=(b);++i)
#define ford(i,a,b) for(int i=(a);i>=(b);--i)

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector <int> a(n+1);
	vector <int> b(m+1);
	forn(i, 1, n)
		cin >> a[i];
	forn(i, 1, m)
		cin >> b[i];
	sort(a.begin()+1, a.end());
	sort(b.begin()+1, b.end());
	if (max(2*a[1], a[n]) < b[1])
		cout << max(2*a[1], a[n]);
	else
		cout << -1;
	return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#define File_in freopen("input.txt", "r", stdin)
#define File_out freopen("output.txt", "w", stdout)
#define yep  cout << "YES" << endl
#define nope cout << "NO" << endl
#define FOR(i,b,n) for(int i=b; i<=n; i++)
#define RFOR(i,n,b) for(int i=n; i>=b; i--)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int main()
{
    int n,m, ans = -1,ans2 = 999;
    cin >> n >> m;
    bool z = 0;
    bool bb = 1;
    bool z1 = 0;
    bool bb1 = 1;
    vector <int> a(n+1,0),b(m+1,0);
    FOR(i,0,n-1)
    {
        cin >> a[i];
        ans = max(ans,a[i]);
        ans2 = min(ans2,a[i]);
    }
    FOR(i,0,m-1)
    {
        cin >> b[i];
    }
    FOR(i,0,n-1)
    {
        if (a[i]<=ans/2)
        {
            z  = 1;
            break;
        }
    }
    FOR(i,0,m-1)
    {
        if (b[i]<=ans)
        {
            bb = 0;
            break;
        }
    }
    ans2 = ans2*2;
    FOR(i,0,n-1)
    {
        if (a[i]<=ans2/2)
        {
            z1  = 1;
            break;
        }
    }
    FOR(i,0,m-1)
    {

        if (b[i]<=ans2)
        {
            bb1 = 0;
            break;
        }
    }

    if ( bb && z)
    {
        cout << ans << endl;
    }
    else if (bb1 && z1)
    {
        cout << ans2 << endl;
    }
    else
    {
        cout << -1 << endl;
    }

}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#define File_in freopen("input.txt", "r", stdin)
#define File_out freopen("output.txt", "w", stdout)
#define yep  cout << "YES" << endl
#define nope cout << "NO" << endl
#define FOR(i,b,n) for(int i=b; i<=n; i++)
#define RFOR(i,n,b) for(int i=n; i>=b; i--)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int main()
{
    int n,m, ans = -1,ans2;
    cin >> n >> m;
    bool z = 0;
    bool bb = 1;
    bool z1 = 0;
    bool bb1 = 1;
    vector <int> a(n+1,0),b(m+1,0);
    FOR(i,0,n-1)
    {
        cin >> a[i];
        ans = max(ans,a[i]);
    }
    FOR(i,0,m-1)
    {
        cin >> b[i];
    }
    FOR(i,0,n-1)
    {
        if (a[i]<=ans/2)
        {
            z  = 1;
            break;
        }
    }
    FOR(i,0,m-1)
    {
        if (b[i]<=ans)
        {
            bb = 0;
            break;
        }
    }
    ans2 = ans*2;
    FOR(i,0,n-1)
    {
        if (a[i]<=ans2/2)
        {
            z1  = 1;
            break;
        }
    }
    FOR(i,0,m-1)
    {
        if (b[i]<=ans2)
        {
            bb1 = 0;
            break;
        }
    }

    if ( bb && z)
    {
        cout << ans << endl;
    }
    else if (bb1 && z1)
    {
        cout << ans2 << endl;
    }
    else
    {
        cout << -1 << endl;
    }

}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#define File_in freopen("input.txt", "r", stdin)
#define File_out freopen("output.txt", "w", stdout)
#define yep  cout << "YES" << endl
#define nope cout << "NO" << endl
#define FOR(i,b,n) for(int i=b; i<=n; i++)
#define RFOR(i,n,b) for(int i=n; i>=b; i--)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int main()
{
    int n,m, ans = -1,ans2 = 0,ans3 = 999 ;
    cin >> n >> m;
    bool z1 = 0;
    bool bb1 = 1;
    bool z2 = 0;
    bool bb2 = 1;
    bool z3 = 0;
    bool bb3 = 1;
    vector <int> a(n+1,0),b(m+1,0);
    FOR(i,0,n-1)
    {
        cin >> a[i];
        ans = max(ans,a[i]);
        ans3 = min(ans3,a[i]);
    }
    FOR(i,0,m-1)
    {
        cin >> b[i];
    }

    FOR(i,0,n-1)
    {
        if (a[i]<=ans/2)
        {
            z1  = 1;
            break;
        }
    }
    FOR(i,0,m-1)
    {
        if (b[i]<=ans)
        {
            bb1 = 0;
            break;
        }
    }
    ans2 = ans*2;
    FOR(i,0,n-1)
    {
        if (a[i]<=ans2/2)
        {
            z2  = 1;
            break;
        }
    }
    FOR(i,0,m-1)
    {
        if (b[i]<=ans2)
        {
            bb2 = 0;
            break;
        }
    }

    ans3 *=2;
    z3 = 1;
    FOR(i,0,n-1)
    {
        if (ans3<=a[i])
        {
            z3  = 0;
            break;
        }
    }
    FOR(i,0,m-1)
    {
        if (b[i]<=ans3)
        {
            bb3 = 0;
            break;
        }
    }

    if ( bb1 && z1)
    {
        cout << ans << endl;
    }
    else if (bb3 && z3)
    {
        cout << ans3 << endl;
    }
    else if (bb2 && z2)
    {
        cout << ans2 << endl;
    }
    else
    {
        cout << -1 << endl;
    }

}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <ctime>
#include <iomanip>

using namespace std;

int valids[100], invalids[100];

int main(int argc, char* argv[])
{
	//ifstream fin("input.txt");
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> valids[i];
	for (int i = 0; i < m; i++)
		cin >> invalids[i];

	sort(valids, valids + n);
	sort(invalids, invalids + m);
	reverse(valids, valids + n);
	reverse(invalids, invalids + m);

	/*for (int i = 0; i < n; i++)
		cout << valids[i] << " ";
	cout << '\n';
	for (int i = 0; i < m; i++)
		cout << invalids[i] << " ";
	cout << '\n';*/

	int val = valids[0];
	bool good = true;
	for (int j = 0; j < m; j++) {
		if (invalids[j] <= val) {
			good = false;
			break;
		}
	}
	if (good) {
		good = false;
		for (int i = 1; i < n; i++) {
			if ((valids[i] * 2) <= val) {
				good = true;
				break;
			}
		}
	}

	if (good) {
		cout << val << endl;
	} else {
		cout << -1 << endl;
	}

	getchar();
	return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <ctime>
#include <iomanip>

using namespace std;

int valids[101], invalids[101];

int main(int argc, char* argv[])
{
	//ifstream fin("input.txt");
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> valids[i];
	for (int i = 0; i < m; i++)
		cin >> invalids[i];

	sort(valids, valids + n);
	sort(invalids, invalids + m);
	reverse(valids, valids + n);
	reverse(invalids, invalids + m);

	/*for (int i = 0; i < n; i++)
		cout << valids[i] << " ";
	cout << '\n';
	for (int i = 0; i < m; i++)
		cout << invalids[i] << " ";
	cout << '\n';*/

	int val = valids[0];
	bool good = true;
	for (int j = 0; j < m; j++) {
		if (invalids[j] <= val) {
			good = false;
			break;
		}
	}
	if (good) {
		good = false;
		if (n == 1) {
			if (invalids[0] - valids[0] * 2 >= 1) {
				good = true;
				val = valids[0] * 2;
			}
		} else {
			for (int i = n-1; i >= 1; i--) {
				if ((valids[i] * 2) < invalids[m-1]) {
					good = true;
					if (valids[i] * 2 > valids[0]) {
						val = valids[i] * 2;
					}
					break;
				}
			}
		}
	}

	if (good) {
		cout << val << endl;
	} else {
		cout << -1 << endl;
	}

	getchar();
	return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <ctime>
#include <iomanip>

using namespace std;

int valids[100], invalids[100];

int main(int argc, char* argv[])
{
	//ifstream fin("input.txt");
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> valids[i];
	for (int i = 0; i < m; i++)
		cin >> invalids[i];

	sort(valids, valids + n);
	sort(invalids, invalids + m);
	reverse(valids, valids + n);
	reverse(invalids, invalids + m);

	/*for (int i = 0; i < n; i++)
		cout << valids[i] << " ";
	cout << '\n';
	for (int i = 0; i < m; i++)
		cout << invalids[i] << " ";
	cout << '\n';*/

	int val = valids[0];
	bool good = true;
	for (int j = 0; j < m; j++) {
		if (invalids[j] <= val) {
			good = false;
			break;
		}
	}
	if (good) {
		good = false;
		if (n == 1) {
			if (invalids[0] - valids[0] * 2 >= 1) {
				good = true;
				val = valids[0] * 2;
			}
		} else {
			for (int i = 1; i < n; i++) {
				if ((valids[i] * 2) <= val) {
					good = true;
					break;
				}
			}
		}
	}

	if (good) {
		cout << val << endl;
	} else {
		cout << -1 << endl;
	}

	getchar();
	return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <ctime>
#include <iomanip>

using namespace std;

int valids[101], invalids[101];

int main(int argc, char* argv[])
{
	//ifstream fin("input.txt");
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> valids[i];
	for (int i = 0; i < m; i++)
		cin >> invalids[i];

	sort(valids, valids + n);
	sort(invalids, invalids + m);
	reverse(valids, valids + n);
	reverse(invalids, invalids + m);

	/*for (int i = 0; i < n; i++)
		cout << valids[i] << " ";
	cout << '\n';
	for (int i = 0; i < m; i++)
		cout << invalids[i] << " ";
	cout << '\n';*/

	int val = valids[0];
	bool good = true;
	for (int j = 0; j < m; j++) {
		if (invalids[j] <= val) {
			good = false;
			break;
		}
	}
	if (good) {
		good = false;
		if (n == 1) {
			if (invalids[0] - valids[0] * 2 >= 1) {
				good = true;
				val = valids[0] * 2;
			}
		} else {
			for (int i = 1; i < n; i++) {
				if ((valids[i] * 2) < invalids[m-1]) {
					good = true;
					if (valids[i] * 2 > valids[0]) {
						val = valids[i] * 2;
					}
					break;
				}
			}
		}
	}

	if (good) {
		cout << val << endl;
	} else {
		cout << -1 << endl;
	}

	getchar();
	return 0;
}


#include <bits/stdc++.h>
using namespace std ;
int main(){
    int n, m, mx = -1, mn = INT_MAX;
    cin >> n >> m;
    while(n--){
        int x; cin >> x;
        mx = max(mx, x);
        mn = min(mn, x);
    }
    mx = max(mn * 2, mx);
    mn = INT_MAX;
    while(m--){
        int x; cin >> x;
        mn = min(mn, x);
    }
    if(mn > mx) cout << mx;
    else cout << -1;
}


#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int n,m,i,j,x;
	int s[102],s1[102];
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		int t=0;
		int mix=-10000;
		int max=10000;
		int mix1=-10000;
		int max1=10000;
		for(i=0;i<n;i++)
		{scanf("%d",&s[i]);
		 if(s[i]<=max)
		 max=s[i];

		}
		for(i=0;i<m;i++)
		{scanf("%d",&s1[i]);
		 if(s1[i]<=max1)
		 max1=s1[i];

		}
		for(i=0;i<n;i++)
		{
			if(s[i]>=mix)
			mix=s[i];
		}
		for(i=0;i<m;i++)
		{
			if(s1[i]>=mix1)
			mix1=s1[i];
		}

	if(mix<0)
	t=1;
	if(mix<2*max)
	t=1;
	/*for(i=0;i<n;i++)
	{
		if(s[i]==mix)
		break;
	}
	if(i>4)
	t=1;*/
	if(mix>max1)
	t=1;
	if(t==1)
	printf("-1\n");
	else
	printf("%d\n",mix);

	}
	return 0;
}


#include<stdio.h>
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}
int main()
{
	int n,m,i,j,ans;
	int a[102];
	int b[102];
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(i=0;i<n;i++)
		scanf("%d",&a[i]);
		for(i=0;i<m;i++)
		scanf("%d",&b[i]);
		qsort(a,n,sizeof(a[0]),cmp);
		qsort(b,m,sizeof(b[0]),cmp);
		if(a[0]*2<a[n-1])
		 ans=a[n-1];
		else
		 ans=a[0]*2;
		printf("%d\n",ans<b[m-1]?ans:-1);
	}
	return 0;
}


#include<stdio.h>
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}
int main()
{
	int n,m,i,j,ans;
	int a[102];
	int b[102];
	while(scanf("%d%d",&n,&m)!=EOF)
	{ ans=0;
		for(i=0;i<n;i++)
		scanf("%d",&a[i]);
		for(i=0;i<m;i++)
		scanf("%d",&b[i]);
		qsort(a,n,sizeof(a[0]),cmp);
		qsort(b,m,sizeof(b[0]),cmp);
		if(a[0]*2<a[n-1])
		 ans=a[n-1];
			if(a[0]*2>a[n-1])
		 ans=a[0]*2;
		printf("%d\n",ans<b[m-1]?ans:-1);
	}
	return 0;
}


#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int n,m,i,j,x;
	int s[102],s1[102];
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		int t=0;
		int mix=-10000;
		int max=10000;
		int mix1=-10000;
		int max1=10000;
		for(i=0;i<n;i++)
		{scanf("%d",&s[i]);
		 if(s[i]<=max)
		 max=s[i];

		}
		for(i=0;i<m;i++)
		{scanf("%d",&s1[i]);
		 if(s1[i]<=max1)
		 max1=s1[i];

		}
		for(i=0;i<n;i++)
		{
			if(s[i]>=mix)
			mix=s[i];
		}
		for(i=0;i<m;i++)
		{
			if(s1[i]>=mix1)
			mix1=s1[i];
		}

	if(mix<0)
	t=1;
	if(mix<2*max)
	t=1;
	/*for(i=0;i<n;i++)
	{
		if(s[i]==mix)
		break;
	}
	if(i>4)
	*/t=1;
	if(mix>max1)
	t=1;
	if(t==1)
	printf("-1\n");
	else
	printf("%d\n",mix);

	}
	return 0;
}


#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int n,m,i,j,ans;
	int a[102];
	int b[102];
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(i=0;i<n;i++)
		scanf("%d",&a[i]);
		for(i=0;i<m;i++)
		scanf("%d",&b[i]);
		sort(a,a+n);
		sort(b,b+m);
		if(a[0]*2<=a[n-1])
		 ans=a[n-1];
		else
		 ans=a[0]*2;
		printf("%d\n",ans<b[m-1]?ans:-1);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <algorithm>

using namespace std;

#define N 100005
#define M 400010
#define INF INT_MAX

const int maxn=500;
inline int max(int a,int b)
{
    return a>b?a:b;
}

inline int min(int a,int b)
{
    return a<b?a:b;
}

int main()
{
    int a[maxn],b[maxn];
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<m;i++)
        cin>>b[i];

    sort(a,a+n);
    sort(b,b+m);
    int res=max(2*a[0],a[n-1]);
    printf("%d\n",res<b[0]?res:-1);
    return 0;
}


#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int n,m,i,j,x;
	int s[102],s1[102];
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		int t=0;
		int mix=-10000;
		int max=10000;
		int mix1=-10000;
		int max1=10000;
		for(i=0;i<n;i++)
		{scanf("%d",&s[i]);
		 if(s[i]<=max)
		 max=s[i];

		}
		for(i=0;i<m;i++)
		{scanf("%d",&s1[i]);
		 if(s1[i]<=max1)
		 max1=s1[i];

		}
		for(i=0;i<n;i++)
		{
			if(s[i]>=mix)
			mix=s[i];
		}
		for(i=0;i<m;i++)
		{
			if(s1[i]>=mix1)
			mix1=s1[i];
		}

	if(mix<0)
	t=1;
	if(mix<2*max)
	t=1;
	for(i=0;i<n;i++)
	{
		if(s[i]==mix)
		break;
	}
	if(i>4)
	t=1;
	if(mix>max1)
	t=1;
	if(t==1)
	printf("-1\n");
	else
	printf("%d\n",mix);

	}
	return 0;
}


#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int n,m,i,j;
	int a[102];
	int b[102];
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(i=0;i<n;i++)
		scanf("%d",&a[i]);
		for(i=0;i<m;i++)
		scanf("%d",&b[i]);
		sort(a,a+n);
		sort(b,b+m);
		int ans=max(a[0]*2,a[n-1]);
		printf("%d\n",ans<b[m-1]?ans:-1);
	}
	return 0;
}


#include<stdio.h>
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}
int main()
{
	int n,m,i,j,ans;
	int a[102];
	int b[102];
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(i=0;i<n;i++)
		scanf("%d",&a[i]);
		for(i=0;i<m;i++)
		scanf("%d",&b[i]);
		qsort(a,n,sizeof(a[0]),cmp);
		qsort(b,m,sizeof(b[0]),cmp);
		if(a[0]*2<=a[n-1])
		 ans=a[n-1];
		else
		 ans=a[0]*2;
		printf("%d\n",ans<b[m-1]?ans:-1);
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <sstream>
using namespace std;
/*
5
3 2 -1 2 11
-1 2 2 3 11
2 1 1 1 1
1 1 1 1 1
*/
int main(){
    int n, m;
    cin >> n >> m;
    int mn = INT_MAX, mn1 = INT_MAX, mx = INT_MIN, mx1 = INT_MIN, x;
    for (int i = 0; i < n; i++){
        cin >> x;
        mn = min(x, mn);
        mx = max(x, mx);
    }
    for (int i = 0; i < m; i++){
        cin >> x;
        mn1 = min(mn1, x);
    }
    if (max(2 * mn, mx) < mn1){
        cout << max(mn * 2, mx) << "\n";
    }
    else cout << "-1\n";
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n)  for(int i=(int)s; i<int(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define pss pair<string, string>
#define ull unsigned long long int
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD= 998244353;
template <typename T>
inline void print(T x){cout<<x<<"\n";}
template <typename T>
inline void printvec(T x){for(auto a:x) cout<<a<<' '; cout<<'\n';}
// -----------------------------------------------------------------------

struct custom{
    bool operator()(const pii &p1, const pii &p2)const{
                if(p1.F==p2.F)
                {
                    return true;
                }
                return p1.F>p2.F;
        }
};

// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = (res*a)%MOD;
        a = (a*a)%MOD;
        b >>= 1;
    }
    return res;
}
// ---------------------------------------------------------------------
const ll N = 1e4+10, inf=4e18;

void solve()
{
    ll n, su=0;
    cin>>n;
    vll v(n+1);
    forn(i,1,n+1){
        cin>>v[i];
        su+=v[i];
    }
    if(su%n != 0)
    {
        cout<<-1<<'\n';
        return;
    }
    ll k=su/n;
    std::vector<pair<pll, ll>> ans;
    forn(i,2,n+1)
    {
        ll req = i- v[i]%i;
        ans.pb({{1, i}, req});
        v[i]+=req;
        ans.pb({{i, 1}, req/i});
    }
    forn(i,2,n+1)
    {
       ans.pb({{1, i}, k});
    }
    cout<<ans.size()<<'\n';
    for(auto p:ans)
        cout<<p.F.F<<' '<<p.F.S<<' '<<p.S<<'\n';
    //printvec(v);

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    cin>>test;
    clock_t z=clock();
    forn(tes, 0, test)
    {
        solve();
    }
    debug("Total Time:%.4f\n",(double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n)  for(int i=(int)s; i<int(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define pss pair<string, string>
#define ull unsigned long long int
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD= 998244353;
template <typename T>
inline void print(T x){cout<<x<<"\n";}
template <typename T>
inline void printvec(T x){for(auto a:x) cout<<a<<' '; cout<<'\n';}
// -----------------------------------------------------------------------

struct custom{
    bool operator()(const pii &p1, const pii &p2)const{
                if(p1.F==p2.F)
                {
                    return true;
                }
                return p1.F>p2.F;
        }
};

// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = (res*a)%MOD;
        a = (a*a)%MOD;
        b >>= 1;
    }
    return res;
}
// ---------------------------------------------------------------------
const ll N = 1e4+10, inf=4e18;

void solve()
{
    ll n, su=0;
    cin>>n;
    vll v(n+1);
    forn(i,1,n+1){
        cin>>v[i];
        su+=v[i];
    }
    if(su%n != 0)
    {
        cout<<-1<<'\n';
        return;
    }
    ll k=su/n;
    std::vector<pair<pll, ll>> ans;
    forn(i,2,n+1)
    {
        if(v[i]>k)
        {
            ll x = (v[i]-k+i-1)/i;
            ans.pb({{i, 1}, x});
            v[i] = v[i] - x*i;
            v[1]+=x*i;
        }
    }
    forn(i,2,n+1)
    {
        if(v[i]<k)
        {
            ll x = k-v[i];
            ans.pb({{1, i}, x});
            v[i]+=x;
            v[1]-=x;
        }
    }
    cout<<ans.size()<<'\n';
    for(auto p:ans)
        cout<<p.F.F<<' '<<p.F.S<<' '<<p.S<<'\n';
    //printvec(v);

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    cin>>test;
    clock_t z=clock();
    forn(tes, 0, test)
    {
        solve();
    }
    debug("Total Time:%.4f\n",(double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n)  for(int i=(int)s; i<int(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define pss pair<string, string>
#define ull unsigned long long int
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
const ll MOD= 998244353;
template <typename T>
inline void print(T x){cout<<x<<"\n";}
template <typename T>
inline void printvec(T x){for(auto a:x) cout<<a<<' '; cout<<'\n';}
// -----------------------------------------------------------------------

struct custom{
    bool operator()(const pii &p1, const pii &p2)const{
                if(p1.F==p2.F)
                {
                    return true;
                }
                return p1.F>p2.F;
        }
};

// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = (res*a)%MOD;
        a = (a*a)%MOD;
        b >>= 1;
    }
    return res;
}
// ---------------------------------------------------------------------
const ll N = 1e4+10, inf=4e18;

void solve()
{
    ll n, su=0;
    cin>>n;
    vll v(n+1);
    forn(i,1,n+1){
        cin>>v[i];
        su+=v[i];
    }
    if(su%n != 0)
    {
        cout<<-1<<'\n';
        return;
    }
    ll k=su/n;
    std::vector<pair<pll, ll>> ans;
    forn(i,2,n+1)
    {
        if(v[i]>k)
        {
            ll x = 0;
            while((v[i]-x*i)>k)
            {
                x++;
            }
            if(v[i]-x*i<0)
                continue;
            v[i]-=x*i;
            v[1]+=x*i;
            ans.pb({{i, 1}, x});
        }
    }
    forn(i,2,n+1)
    {
        if(v[i]>k)
        {
            ll x = 0;
            while((v[i]-x*i)>k)
            {
                x++;
            }
            if(v[i]-x*i<0)
            {
                ans.pb({{1, i}, i});
                v[1]-=i;
                v[i]+=i;
                v[i]-=x*i;
                ans.pb({{i, 1}, x});
            }

        }
    }
    forn(i,2,n+1)
    {
        if(v[i]<k)
        {
            ll x = k-v[i];
            ans.pb({{1, i}, x});
            v[i]+=x;
            v[1]-=x;
        }
    }
    cout<<ans.size()<<'\n';
    for(auto p:ans)
        cout<<p.F.F<<' '<<p.F.S<<' '<<p.S<<'\n';
    //printvec(v);

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    cin>>test;
    clock_t z=clock();
    forn(tes, 0, test)
    {
        solve();
    }
    debug("Total Time:%.4f\n",(double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005                 // 1e5 + 5
#define MOD 1000000007LL            // 1e9 + 7
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18

#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vll>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;

int main()
{
  fast_io();
#ifndef ONLINE_JUDGE
  freopen("../input.txt", "r", stdin);
  freopen("../output.txt", "w", stdout);
#endif

  cin>>tc;
  while(tc--) {
    cin>>n;
    vll arr(n, 0);
    ll sum = 0;
    rep(i, 0, n) cin>>arr[i], sum += arr[i];
    if(sum%n != 0) {
      cout<<-1;
      newl;
      continue;
    }
    vector<pair<pll, ll>> ans;

    rep(i, 1, n) {
      // make it divisible by i;
      if(arr[i]%(i+1) != 0) {
        ans.pb({{1, i+1}, arr[i]%(i+1)});
      }
      // make it zero;
      ans.pb({{1, i+1}, arr[i]});
    }

    rep(i, 1, n) {
      ans.pb({{1, i+1}, sum/n});
    }

    cout<<sz(ans);
    newl;
    rep(i, 0, sz(ans)) {
      cout<<ans[i].f.f<<" "<<ans[i].f.s<<" "<<ans[i].s;
      newl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005                 // 1e5 + 5
#define MOD 1000000007LL            // 1e9 + 7
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18

#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vll>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;

int main()
{
  fast_io();
#ifndef ONLINE_JUDGE
  freopen("../input.txt", "r", stdin);
  freopen("../output.txt", "w", stdout);
#endif

  cin>>tc;
  while(tc--) {
    cin>>n;
    vll arr(n, 0);
    ll sum = 0;
    rep(i, 0, n) cin>>arr[i], sum += arr[i];
    if(sum%n != 0) {
      cout<<-1;
      newl;
      continue;
    }
    vector<pair<pll, ll>> ans;
    //  first index in pair will get reduced.
    rep(i, 1, n) {
      // make it divisible by i;
      if(arr[i]%(i+1) != 0) {
        ans.pb({{1, i+1}, (i+1) - arr[i]%(i+1)});
      }
      // make it zero;
      ans.pb({{i+1, 1}, arr[i]/(i+1)});
    }

    rep(i, 1, n) {
      ans.pb({{1, i+1}, sum/n});
    }

    cout<<sz(ans);
    newl;
    rep(i, 0, sz(ans)) {
      cout<<ans[i].f.f<<" "<<ans[i].f.s<<" "<<ans[i].s;
      newl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005                 // 1e5 + 5
#define MOD 1000000007LL            // 1e9 + 7
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18

#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vll>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;

int main()
{
  fast_io();
#ifndef ONLINE_JUDGE
  freopen("../input.txt", "r", stdin);
  freopen("../output.txt", "w", stdout);
#endif

  cin>>tc;
  while(tc--) {
    cin>>n;
    vll arr(n, 0);
    ll sum = 0;
    rep(i, 0, n) cin>>arr[i], sum += arr[i];
    if(sum%n != 0) {
      cout<<-1;
      newl;
      continue;
    }
    vector<pair<pll, ll>> ans;

    rep(i, 1, n) {
      // make it divisible by i;
      if(arr[i]%i != 0) {
        ans.pb({{0, i}, arr[i]%i});
      }
      // make it zero;
      ans.pb({{0, i}, arr[i]/i});
    }

    rep(i, 1, n) {
      ans.pb({{0, i}, sum/n});
    }

    cout<<sz(ans);
    newl;
    rep(i, 0, sz(ans)) {
      cout<<ans[i].f.f<<" "<<ans[i].f.s<<" "<<ans[i].s;
      newl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005                 // 1e5 + 5
#define MOD 1000000007LL            // 1e9 + 7
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18

#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vll>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;

int main()
{
  fast_io();
#ifndef ONLINE_JUDGE
  freopen("../input.txt", "r", stdin);
  freopen("../output.txt", "w", stdout);
#endif

  cin>>tc;
  while(tc--) {
    cin>>n;
    vll arr(n, 0);
    ll sum = 0;
    rep(i, 0, n) cin>>arr[i], sum += arr[i];
    if(sum%n != 0) {
      cout<<-1;
      newl;
      continue;
    }
    vector<pair<pll, ll>> ans;

    rep(i, 1, n) {
      // make it divisible by i;
      if(arr[i]%i != 0) {
        ans.pb({{1, i+1}, arr[i]%i});
      }
      // make it zero;
      ans.pb({{1, i+1}, arr[i]/i});
    }

    rep(i, 1, n) {
      ans.pb({{1, i+1}, sum/n});
    }

    cout<<sz(ans);
    newl;
    rep(i, 0, sz(ans)) {
      cout<<ans[i].f.f<<" "<<ans[i].f.s<<" "<<ans[i].s;
      newl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005                 // 1e5 + 5
#define MOD 1000000007LL            // 1e9 + 7
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18

#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vll>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;

int main()
{
  fast_io();
#ifndef ONLINE_JUDGE
  freopen("../input.txt", "r", stdin);
  freopen("../output.txt", "w", stdout);
#endif

  cin>>tc;
  while(tc--) {
    cin>>n;
    vll arr(n, 0);
    ll sum = 0;
    rep(i, 0, n) cin>>arr[i], sum += arr[i];
    if(sum%n != 0) {
      cout<<-1;
      newl;
      continue;
    }
    vector<pair<pll, ll>> ans;

    rep(i, 1, n) {
      // make it divisible by i;
      if(arr[i]%(i+1) != 0) {
        ans.pb({{1, i+1}, arr[i]%(i+1)});
      }
      // make it zero;
      ans.pb({{1, i+1}, arr[i]/(i+1)});
    }

    rep(i, 1, n) {
      ans.pb({{1, i+1}, sum/n});
    }

    cout<<sz(ans);
    newl;
    rep(i, 0, sz(ans)) {
      cout<<ans[i].f.f<<" "<<ans[i].f.s<<" "<<ans[i].s;
      newl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005                 // 1e5 + 5
#define MOD 1000000007LL            // 1e9 + 7
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18

#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vll>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;

int main()
{
  fast_io();
#ifndef ONLINE_JUDGE
  freopen("../input.txt", "r", stdin);
  freopen("../output.txt", "w", stdout);
#endif

  cin>>tc;
  while(tc--) {
    cin>>n;
    vll arr(n, 0);
    ll sum = 0;
    rep(i, 0, n) cin>>arr[i], sum += arr[i];
    if(sum%n != 0) {
      cout<<-1;
      newl;
      continue;
    }
    vector<pair<pll, ll>> ans;

    rep(i, 1, n) {
      // make it divisible by i;
      if(arr[i]%(i+1) != 0) {
        ans.pb({{1, i+1}, (i+1) - arr[i]%(i+1)});
      }
      // make it zero;
      ans.pb({{1, i+1}, arr[i]});
    }

    rep(i, 1, n) {
      ans.pb({{1, i+1}, sum/n});
    }

    cout<<sz(ans);
    newl;
    rep(i, 0, sz(ans)) {
      cout<<ans[i].f.f<<" "<<ans[i].f.s<<" "<<ans[i].s;
      newl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005                 // 1e5 + 5
#define MOD 1000000007LL            // 1e9 + 7
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18

#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vll>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;

int main()
{
  fast_io();
#ifndef ONLINE_JUDGE
  freopen("../input.txt", "r", stdin);
  freopen("../output.txt", "w", stdout);
#endif

  cin>>tc;
  while(tc--) {
    cin>>n;
    vll arr(n, 0);
    ll sum = 0;
    rep(i, 0, n) cin>>arr[i], sum += arr[i];
    if(sum%n != 0) {
      cout<<-1;
      newl;
      continue;
    }
    vector<pair<pll, ll>> ans;
    //  first index in pair will get reduced.
    rep(i, 1, n) {
      // make it divisible by i;
      if(arr[i]%(i+1) != 0) {
        ans.pb({{1, i+1}, (i+1) - arr[i]%(i+1)});
        arr[i] += (i+1) - arr[i]%(i+1);
      }
      // make it zero;
      ans.pb({{i+1, 1}, arr[i]/(i+1)});
    }

    rep(i, 1, n) {
      ans.pb({{1, i+1}, sum/n});
    }

    cout<<sz(ans);
    newl;
    rep(i, 0, sz(ans)) {
      cout<<ans[i].f.f<<" "<<ans[i].f.s<<" "<<ans[i].s;
      newl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005                 // 1e5 + 5
#define MOD 1000000007LL            // 1e9 + 7
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18

#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vll>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;

int main()
{
  fast_io();
#ifndef ONLINE_JUDGE
  freopen("../input.txt", "r", stdin);
  freopen("../output.txt", "w", stdout);
#endif

  cin>>tc;
  while(tc--) {
    cin>>n;
    vll arr(n, 0);
    ll sum = 0;
    rep(i, 0, n) cin>>arr[i], sum += arr[i];
    if(sum%n != 0) {
      cout<<-1;
      newl;
      continue;
    }
    vector<pair<pll, ll>> ans;

    rep(i, 1, n) {
      // make it divisible by i;
      if(arr[i]%i != 0) {
        ans.pb({{1, i}, arr[i]%i});
      }
      // make it zero;
      ans.pb({{1, i}, arr[i]/i});
    }

    rep(i, 1, n) {
      ans.pb({{1, i}, sum/n});
    }

    cout<<sz(ans);
    newl;
    rep(i, 0, sz(ans)) {
      cout<<ans[i].f.f<<" "<<ans[i].f.s<<" "<<ans[i].s;
      newl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <pair<int, int>, int> tri;
typedef pair <ll, ll> pll;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
// [&](int x, int y){ return v[x] < v[y]}

void solve(){

	int n;
	cin >> n;
	int a[n+3];
	int sum = 0;
	for(int i=1; i<=n; i++){
		scanf("%d", &a[i]);
		sum += a[i];
	}
	if(sum%n){
		cout << -1 << endl;
		return;
	}
	int mu = sum/n;

	if(n==1){
		cout << 0 << endl;
		return;
	}

	vector<tri> vec;

	for(int i=2; i<=n; i++){
		if(a[i]%i > mu){
			cout << -1 << endl;
			return;
		}
		if(a[i]/n){
			vec.pb({{i, 1}, a[i]/i});
		}
	}
	for(int i=2; i<=n; i++){
		if(a[i]%i < mu){
			vec.pb({{1,i},mu-a[i]%i});
		}
	}
	cout << vec.size() << endl;
	for(int i=0; i<vec.size();i++){
		cout << vec[i].first.first << " " << vec[i].first.second << " " << vec[i].second << endl;
	}

}

int main(void)
{

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <pair<int, int>, int> tri;
typedef pair <ll, ll> pll;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
// [&](int x, int y){ return v[x] < v[y]}

void solve(){

	int n;
	cin >> n;
	int a[n+3];
	int sum = 0;
	for(int i=1; i<=n; i++){
		scanf("%d", &a[i]);
		sum += a[i];
	}
	if(sum%n){
		cout << -1 << endl;
		return;
	}
	int mu = sum/n;

	if(n==1){
		cout << 0 << endl;
		return;
	}

	int tr = a[1];
	vector<tri> vec;
	vector<pii> sur;

	for(int i=2; i<=n; i++){
		if(a[i]/i){
			vec.pb({{i, 1}, a[i]/i});
			tr += (a[i]/i)*i;
		}
		if(a[i]%i > mu){
			sur.pb({i-(a[i]%i), i});
		}
	}

	if(sur.size()){
		sort(sur.begin(), sur.end());

		for(int i=0; i<sur.size(); i++){
			if(tr < sur[i].first){
				cout << -1 << endl;
			}
			vec.pb({{1, sur[i].second}, sur[i].first});
			vec.pb({{sur[i].second,1},1});
			vec.pb({{1, sur[i].second}, mu});
			tr += ((a[sur[i].second]%sur[i].second)-mu);
		}
	}
	for(int i=2; i<=n; i++){
		if(a[i]%i < mu){
			vec.pb({{1,i},mu-a[i]%i});
		}
	}
	cout << vec.size() << endl;
	for(int i=0; i<vec.size();i++){
		cout << vec[i].first.first << " " << vec[i].first.second << " " << vec[i].second << endl;
	}

}

int main(void)
{

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <pair<int, int>, int> tri;
typedef pair <ll, ll> pll;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
// [&](int x, int y){ return v[x] < v[y]}

void solve(){

	int n;
	cin >> n;
	int a[n+3];
	int sum = 0;
	for(int i=1; i<=n; i++){
		scanf("%d", &a[i]);
		sum += a[i];
	}
	if(sum%n){
		cout << -1 << endl;
		return;
	}
	int mu = sum/n;

	if(n==1){
		cout << 0 << endl;
		return;
	}

	vector<tri> vec;
	vector<pii> sur;

	for(int i=2; i<=n; i++){
		vec.pb({{1,i}, i-a[i]%i});
		vec.pb({{i,1}, (a[i]+i-a[i]%i)/i});
	}

	for(int i=2; i<=n; i++){
		vec.pb({{1,i},mu});
	}
	cout << vec.size() << endl;
	for(int i=0; i<vec.size();i++){
		cout << vec[i].first.first << " " << vec[i].first.second << " " << vec[i].second << endl;
	}

}

int main(void)
{

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <pair<int, int>, int> tri;
typedef pair <ll, ll> pll;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
// [&](int x, int y){ return v[x] < v[y]}

void solve(){

	int n;
	cin >> n;
	int a[n+3];
	int sum = 0;
	for(int i=1; i<=n; i++){
		scanf("%d", &a[i]);
		sum += a[i];
	}
	if(sum%n){
		cout << -1 << endl;
		return;
	}
	int mu = sum/n;

	if(n==1){
		cout << 0 << endl;
		return;
	}

	int tr = a[1];
	vector<tri> vec;
	vector<pii> sur;

	for(int i=2; i<=n; i++){
		if(a[i]/i){
			vec.pb({{i, 1}, a[i]/i});
			tr += (a[i]/i)*i;
		}
		if(a[i]%i > mu){
			sur.pb({i-(a[i]%i), i});
		}
	}

	if(sur.size()){
		sort(sur.rbegin(), sur.rend());
		if(sur[0].first > tr){
			cout << -1 << endl;
			return;
		}
		for(int i=0; i<sur.size(); i++){
			vec.pb({{1, sur[i].second}, sur[i].first});
			vec.pb({{sur[i].second,1},1});
			vec.pb({{1, sur[i].second}, mu});
		}
	}

	for(int i=2; i<=n; i++){
		if(a[i]%i < mu){
			vec.pb({{1,i},mu-a[i]%i});
		}
	}
	cout << vec.size() << endl;
	for(int i=0; i<vec.size();i++){
		cout << vec[i].first.first << " " << vec[i].first.second << " " << vec[i].second << endl;
	}

}

int main(void)
{

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <pair<int, int>, int> tri;
typedef pair <ll, ll> pll;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
// [&](int x, int y){ return v[x] < v[y]}

void solve(){

	int n;
	cin >> n;
	int a[n+3];
	int sum = 0;
	for(int i=1; i<=n; i++){
		scanf("%d", &a[i]);
		sum += a[i];
	}
	if(sum%n){
		cout << -1 << endl;
		return;
	}
	int mu = sum/n;

	if(n==1){
		cout << 0 << endl;
		return;
	}

	vector<tri> vec;
	vector<pii> sur;

	for(int i=2; i<=n; i++){
		if(a[i]%i){
			vec.pb({{1,i}, i-a[i]%i});
			vec.pb({{i,1}, 1 + a[i]/i});
		}else{
			vec.pb({{i,1}, a[i]/i});
		}
	}

	for(int i=2; i<=n; i++){
		vec.pb({{1,i},mu});
	}
	cout << vec.size() << endl;
	for(int i=0; i<vec.size();i++){
		cout << vec[i].first.first << " " << vec[i].first.second << " " << vec[i].second << endl;
	}

}

int main(void)
{

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <pair<int, int>, int> tri;
typedef pair <ll, ll> pll;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
// [&](int x, int y){ return v[x] < v[y]}

void solve(){

	int n;
	cin >> n;
	int a[n+3];
	int sum = 0;
	for(int i=1; i<=n; i++){
		scanf("%d", &a[i]);
		sum += a[i];
	}
	if(sum%n){
		cout << -1 << endl;
		return;
	}
	int mu = sum/n;

	if(n==1){
		cout << 0 << endl;
		return;
	}

	int tr = a[1];
	vector<tri> vec;
	vector<pii> sur;

	for(int i=2; i<=n; i++){
		if(a[i]/i){
			vec.pb({{i, 1}, a[i]/i});
			tr += (a[i]/i)*i;
		}
		if(a[i]%i > mu){
			sur.pb({mu+i-(a[i]%i), i});
		}
	}

	if(sur.size()){
		sort(sur.rbegin(), sur.rend());
		if(sur[0].first > tr){
			cout << -1 << endl;
			return;
		}
		for(int i=0; i<sur.size(); i++){
			vec.pb({{1, sur[i].second}, sur[i].first});
			vec.pb({{sur[i].second,1},1});
			tr -= sur[i].first;
			tr += sur[i].second;
		}
	}

	for(int i=2; i<=n; i++){
		if(a[i]%i < mu){
			vec.pb({{1,i},mu-a[i]%i});
		}
	}
	cout << vec.size() << endl;
	for(int i=0; i<vec.size();i++){
		cout << vec[i].first.first << " " << vec[i].first.second << " " << vec[i].second << endl;
	}

}

int main(void)
{

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <pair<int, int>, int> tri;
typedef pair <ll, ll> pll;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
// [&](int x, int y){ return v[x] < v[y]}

void solve(){

	int n;
	cin >> n;
	int a[n+3];
	int sum = 0;
	for(int i=1; i<=n; i++){
		scanf("%d", &a[i]);
		sum += a[i];
	}
	if(sum%n){
		cout << -1 << endl;
		return;
	}
	int mu = sum/n;

	if(n==1){
		cout << 0 << endl;
		return;
	}

	vector<tri> vec;

	for(int i=2; i<=n; i++){
		if(a[i]%i > mu){
			cout << -1 << endl;
			return;
		}
		if(a[i]/i){
			vec.pb({{i, 1}, a[i]/i});
		}
	}
	for(int i=2; i<=n; i++){
		if(a[i]%i < mu){
			vec.pb({{1,i},mu-a[i]%i});
		}
	}
	cout << vec.size() << endl;
	for(int i=0; i<vec.size();i++){
		cout << vec[i].first.first << " " << vec[i].first.second << " " << vec[i].second << endl;
	}

}

int main(void)
{

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node
{
	node(int aa,int bb,int cc){
		a = aa;
		b = bb;
		c = cc;
	}
	int a,b,c;
};
int32_t main(){
    //ok
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		int sum=0;
		for(int i=0;i<n;++i)
			sum = sum + arr[i];
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<node> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int rem = arr[i]%(i+1);
			if(rem!=0){
				ans.push_back(node(1,i+1,i+1-rem));
				arr[0] = arr[0] - (i+1-rem);
				arr[i] = arr[i] + (i+1-rem);
			}
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			ans.push_back(node(i+1,1,x));
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			int diff = sum - arr[i];
			ans.push_back(node(1,i+1,diff));
			arr[0] = arr[0] - diff;
			arr[i] = arr[i] + diff;
		}
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x.a<<" "<<x.b<<" "<<x.c<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node
{
	node(int aa,int bb,int cc){
		a = aa;
		b = bb;
		c = cc;
	}
	int a,b,c;
};
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		int sum=0;
		for(int i=0;i<n;++i)
			sum = sum + arr[i];
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<node> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int rem = arr[i]%(i+1);
			if(rem!=0){
				ans.push_back(node(1,i+1,i+1-rem));
				arr[0] = arr[0] - (i+1-rem);
				arr[i] = arr[i] + (i+1-rem);
			}
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			ans.push_back(node(i+1,1,x));
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			int diff = sum - arr[i];
			ans.push_back(node(1,i+1,diff));
			arr[0] = arr[0] - diff;
			arr[i] = arr[i] + diff;
		}
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x.a<<" "<<x.b<<" "<<x.c<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		int sum=0;
		for(int i=0;i<n;++i)
			sum = sum + arr[i];
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<pair<pair<int,int>,int>> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			ans.push_back({{i+1,1},x});
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			if(arr[i]==sum)
				continue;
			if(arr[i]>sum){
				int diff = arr[i] - sum;
				ans.push_back({{diff,i+1},1});
				arr[i] = arr[i] - diff;
				arr[diff-1] = arr[diff-1] + diff;
			}
			else{
				int diff = sum - arr[i];
				ans.push_back({{1,i+1},diff});
				arr[0] = arr[0] - diff;
				arr[i] = arr[i] + diff;
			}
		}
		if(arr[0]!=sum){
			cout<<-1<<endl;
			continue;
		}
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x.first.first<<" "<<x.first.second<<" "<<x.second<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		int sum=0;
		for(int i=0;i<n;++i)
			sum = sum + arr[i];
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<pair<pair<int,int>,int>> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			// cout<<i+1<<" "<<1<<" "<<x<<endl;
			ans.push_back({{i+1,1},x});
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			if(arr[i]==sum)
				continue;
			if(arr[i]>sum){
				int diff = arr[i] - sum;
				// cout<<diff<<" "<<i+1<<" "<<1<<endl;
				ans.push_back({{diff,i+1},1});
				arr[i] = arr[i] - diff;
				arr[diff-1] = arr[diff-1] + diff;
			}
			else{
				// cout<<1<<" "<<i+1<<" "<<sum-arr[i]<<endl;
				int diff = sum - arr[i];
				ans.push_back({{1,i+1},diff});
				arr[0] = arr[0] - diff;
				arr[i] = arr[i] + diff;
			}
		}
		if(arr[0]!=sum)
			return 0;
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x.first.first<<" "<<x.first.second<<" "<<x.second<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node
{
	node(int aa,int bb,int cc){
		a = aa;
		b = bb;
		c = cc;
	}
	int a,b,c;
};
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		int sum = accumulate(arr.begin(),arr.end(),0);
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<array<int,3>> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int rem = arr[i]%(i+1);
			if(rem!=0){
				ans.push_back({1,i+1,i+1-rem});
				// ans.push_back(node(1,i+1,i+1-rem));
				arr[0] = arr[0] - (i+1-rem);
				arr[i] = arr[i] + (i+1-rem);
			}
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			ans.push_back({i+1,1,x});
			// ans.push_back(node(i+1,1,x));
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			int diff = sum - arr[i];
			ans.push_back({1,i+1,diff});
			// ans.push_back(node(1,i+1,diff));
			arr[0] = arr[0] - diff;
			arr[i] = arr[i] + diff;
		}
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e9;
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		int sum=0;
		for(int i=0;i<n;++i)
			sum = sum + arr[i];
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<pair<pair<int,int>,int>> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			// cout<<i+1<<" "<<1<<" "<<x<<endl;
			ans.push_back({{i+1,1},x});
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			if(arr[i]==sum)
				continue;
			if(arr[i]>sum){
				int diff = arr[i] - sum;
				// cout<<diff<<" "<<i+1<<" "<<1<<endl;
				ans.push_back({{diff,i+1},1});
				arr[i] = arr[i] - diff;
				arr[diff-1] = arr[diff-1] + diff;
			}
			else{
				// cout<<1<<" "<<i+1<<" "<<sum-arr[i]<<endl;
				ans.push_back({{1,i+1},sum-arr[i]});
				arr[0] = arr[0] - (sum-arr[i]);
				arr[i] = arr[i] + (sum - arr[i]);
			}
		}
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x.first.first<<" "<<x.first.second<<" "<<x.second<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		int sum=0;
		for(int i=0;i<n;++i)
			sum = sum + arr[i];
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<pair<pair<int,int>,int>> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int rem = arr[i]%(i+1);
			if(rem!=0 && arr[0]>=(i+1-rem)){
				ans.push_back({{1,i+1},i+1-rem});
				arr[0] = arr[0] - (i+1-rem);
				arr[i] = arr[i] + (i+1-rem);
			}
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			ans.push_back({{i+1,1},x});
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			if(arr[i]==sum)
				continue;
			if(arr[i]>sum){
				int diff = arr[i] - sum;
				ans.push_back({{diff,i+1},1});
				arr[i] = arr[i] - diff;
				arr[diff-1] = arr[diff-1] + diff;
			}
			else{
				int diff = sum - arr[i];
				ans.push_back({{1,i+1},diff});
				arr[0] = arr[0] - diff;
				arr[i] = arr[i] + diff;
			}
		}
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x.first.first<<" "<<x.first.second<<" "<<x.second<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node
{
	node(int a,int b,int c){
		this->a = a;
		this->b = b;
		this->c = c;
	}
	int a,b,c;
};
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		int sum=0;
		for(int i=0;i<n;++i)
			sum = sum + arr[i];
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<node> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int rem = arr[i]%(i+1);
			if(rem!=0){
				ans.push_back(node(1,i+1,i+1-rem));
				arr[0] = arr[0] - (i+1-rem);
				arr[i] = arr[i] + (i+1-rem);
			}
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			ans.push_back(node(i+1,1,x));
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			int diff = sum - arr[i];
			ans.push_back(node(1,i+1,diff));
			arr[0] = arr[0] - diff;
			arr[i] = arr[i] + diff;
		}
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x.a<<" "<<x.b<<" "<<x.c<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		int sum=0;
		for(int i=0;i<n;++i)
			sum = sum + arr[i];
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<pair<pair<int,int>,int>> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			ans.push_back({{i+1,1},x});
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			if(arr[i]==sum)
				continue;
			if(arr[i]>sum){
				int diff = arr[i] - sum;
				ans.push_back({{diff,i+1},1});
				arr[i] = arr[i] - diff;
				arr[diff-1] = arr[diff-1] + diff;
			}
			else{
				int diff = sum - arr[i];
				ans.push_back({{1,i+1},diff});
				arr[0] = arr[0] - diff;
				arr[i] = arr[i] + diff;
			}
		}
		if(arr[0]!=sum){
			cout<<-1<<endl;
			continue;
		}
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x.first.first<<" "<<x.first.second<<" "<<x.second<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node
{
	node(int aa,int bb,int cc){
		a = aa;
		b = bb;
		c = cc;
	}
	int a,b,c;
};
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		int sum = accumulate(arr.begin(),arr.end(),0);
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<array<int,3>> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int rem = arr[i]%(i+1);
			if(rem!=0){
				ans.push_back({1,i+1,i+1-rem});
				// ans.push_back(node(1,i+1,i+1-rem));
				arr[0] = arr[0] - (i+1-rem);
				arr[i] = arr[i] + (i+1-rem);
			}
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			ans.push_back({i+1,1,x});
			// ans.push_back(node(i+1,1,x));
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			int diff = sum - arr[i];
			ans.push_back({1,i+1,diff});
			// ans.push_back(node(1,i+1,diff));
			arr[0] = arr[0] - diff;
			arr[i] = arr[i] + diff;
		}
		cout<<ans.size()<<endl;
		for(auto &[x,y,z]:ans)
			cout<<x<<" "<<y<<" "<<z<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node
{
	node(int a,int b,int c){
		this->a = a;
		this->b = b;
		this->c = c;
	}
	int a,b,c;
};
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		int sum=0;
		for(int i=0;i<n;++i)
			sum = sum + arr[i];
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<node> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int rem = arr[i]%(i+1);
			if(rem!=0){
				ans.push_back(node(1,i=1,i+1-rem));
				arr[0] = arr[0] - (i+1-rem);
				arr[i] = arr[i] + (i+1-rem);
			}
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			ans.push_back(node(i+1,1,x));
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			int diff = sum - arr[i];
			ans.push_back(node(1,i+1,diff));
			arr[0] = arr[0] - diff;
			arr[i] = arr[i] + diff;
		}
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x.a<<" "<<x.b<<" "<<x.c<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		int sum=0;
		for(int i=0;i<n;++i)
			sum = sum + arr[i];
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<pair<pair<int,int>,int>> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int rem = arr[i]%(i+1);
			if(rem!=0){
				ans.push_back({{1,i+1},i+1-rem});
				arr[0] = arr[0] - (i+1-rem);
				arr[i] = arr[i] + (i+1-rem);
			}
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			ans.push_back({{i+1,1},x});
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			if(arr[i]==sum)
				continue;
			if(arr[i]>sum){
				int diff = arr[i] - sum;
				ans.push_back({{diff,i+1},1});
				arr[i] = arr[i] - diff;
				arr[diff-1] = arr[diff-1] + diff;
			}
			else{
				int diff = sum - arr[i];
				ans.push_back({{1,i+1},diff});
				arr[0] = arr[0] - diff;
				arr[i] = arr[i] + diff;
			}
		}
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x.first.first<<" "<<x.first.second<<" "<<x.second<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node
{
	node(int aa,int bb,int cc){
		a = aa;
		b = bb;
		c = cc;
	}
	int a,b,c;
};
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> arr(n);
		for(int i=0;i<n;++i)
			cin>>arr[i];
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		int sum=0;
		for(int i=0;i<n;++i)
			sum = sum + arr[i];
		if(sum%n!=0){
			cout<<-1<<endl;
			continue;
		}
		vector<node> ans;
		sum = sum/n;
		for(int i=1;i<n;++i){
			int rem = arr[i]%(i+1);
			if(rem!=0){
				ans.push_back(node(1,i=1,i+1-rem));
				arr[0] = arr[0] - (i+1-rem);
				arr[i] = arr[i] + (i+1-rem);
			}
			int x = arr[i]/(i+1);
			if(x==0)
				continue;
			ans.push_back(node(i+1,1,x));
			arr[0] = arr[0] + x*(i+1);
			arr[i] = arr[i] - x*(i+1);
		}
		for(int i=n-1;i>0;--i){
			int diff = sum - arr[i];
			ans.push_back(node(1,i+1,diff));
			arr[0] = arr[0] - diff;
			arr[i] = arr[i] + diff;
		}
		cout<<ans.size()<<endl;
		for(auto x:ans)
			cout<<x.a<<" "<<x.b<<" "<<x.c<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#ifdef DEBUG
#define endl endl
#else
#define endl "\n"
#endif

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())
#define UNIQUE(v) \
    SORT(v);      \
    v.resize(distance(v.begin(), unique(v.begin(), v.end())))

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << endl;
}

const ll md = 1e9 + 7;
ll MOD(ll x) {
    ll r = x % md;
    if (r < 0) {
        r += md;
    }
    return r;
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF DBL_MAX
// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 1e18
#define MINF -INF

void solve() {
    ll n;
    cin >> n;
    vector<vll> res;
    vll a(n);
    REP(i, n) {
        cin >> a[i];
    }

    ll sm = accumulate(a.begin(), a.end(), 0);
    if (sm % n != 0) {
        cout << -1 << endl;
        return;
    }

    ll goal = sm / n;

    FOR(i, 1, n) {
        ll rem = a[i] % (i + 1);
        ll need = (i + 1 - rem) % (i + 1);
        res.push_back({1, i + 1, need});
        a[i] += need;
        a[0] -= need;
        res.push_back({i + 1, 1, a[i] / (i + 1)});
        a[0] += a[i];
        a[i] = 0;
    }

    FOR(i, 1, n) {
        res.push_back({1, i + 1, goal});
        a[0] -= goal;
        a[i] += goal;
    }

    FOR(i, 0, n) {
        assert(a[i] == goal);
    }

    cout << res.size() << endl;
    REP(i, res.size()) {
        join(res[i], " ");
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    cin >> tt;

#ifdef DEBUG
    // for (int t = 1; t <= tt || cin.rdbuf()->in_avail(); t++) {
    //     // cout << "Case #" << t << ": ";
    //     solve();
    // }

    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#else
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#endif

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#ifdef DEBUG
#define endl endl
#else
#define endl "\n"
#endif

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())
#define UNIQUE(v) \
    SORT(v);      \
    v.resize(distance(v.begin(), unique(v.begin(), v.end())))

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << endl;
}

const ll md = 1e9 + 7;
ll MOD(ll x) {
    ll r = x % md;
    if (r < 0) {
        r += md;
    }
    return r;
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF DBL_MAX
// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 1e18
#define MINF -INF

void solve() {
    ll n;
    cin >> n;
    vector<vll> res;
    vll a(n);
    REP(i, n) {
        cin >> a[i];
    }

    ll sm = accumulate(a.begin(), a.end(), 0);
    if (sm % n != 0) {
        cout << -1 << endl;
        return;
    }

    ll goal = sm / n;

    FOR(i, 1, n) {
        if (a[i] > goal) {
            ll x = a[i] / (i + 1);
            if (x == 0)
                continue;
            res.push_back({i + 1, 1, x});
            ll reduced = x * (i + 1);
            a[i] -= reduced;
            a[0] += reduced;
        }
    }

    vector<pll> leftIdx;
    FOR(i, 1, n) {
        if (a[i] > goal) {
            assert(i + 1 > a[i]);
            ll left = i + 1 - a[i];
            leftIdx.push_back({left, i});
        }
    }
    SORT(leftIdx);
    for (auto& pr : leftIdx) {
        ll left = pr.first;
        ll i = pr.second;
        res.push_back({1, i + 1, left});
        a[0] -= left;
        assert(a[0] >= 0);
        a[i] += left;
        res.push_back({i + 1, 1, 1});
        a[0] += a[i];
        a[i] = 0;
    }

    FOR(i, 1, n) {
        assert(a[i] <= goal);
        ll extra = goal - a[i];
        if (extra == 0)
            continue;
        res.push_back({1, i + 1, extra});
        a[0] -= extra;
        a[i] += extra;
    }

    REP(i, n) {
        assert(a[i] == goal);
    }

    cout << res.size() << endl;
    REP(i, res.size()) {
        join(res[i], " ");
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    cin >> tt;

#ifdef DEBUG
    // for (int t = 1; t <= tt || cin.rdbuf()->in_avail(); t++) {
    //     // cout << "Case #" << t << ": ";
    //     solve();
    // }

    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#else
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#endif

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#ifdef DEBUG
    #define endl endl
#else
    #define endl "\n"
#endif

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())
#define UNIQUE(v) \
    SORT(v);      \
    v.resize(distance(v.begin(), unique(v.begin(), v.end())))

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << endl;
}

const ll md = 1e9 + 7;
ll MOD(ll x) {
    ll r = x % md;
    if (r < 0) {
        r += md;
    }
    return r;
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF DBL_MAX
// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 1e18
#define MINF -INF

void solve() {
    ll n;
    cin >> n;
    vector<vll> res;
    vll a(n);
    REP(i, n) {
        cin >> a[i];
    }

    ll sm = accumulate(a.begin(), a.end(), 0);
    if (sm % n != 0) {
        cout << -1 << endl;
        return;
    }

    ll goal = sm / n;

    FOR(i, 1, n) {
        if (a[i] > goal) {
            ll x = a[i] / (i + 1);
            res.push_back({i+1, 1, x});
            ll reduced = x * (i+1);
            a[i] -= reduced;
            a[0] += reduced;
        }
    }

    FOR(i, 1, n) {
        assert(a[i] <= goal);
        ll extra = goal - a[i];
        if (extra == 0)
            continue;
        res.push_back({1, i+1, extra});
        a[0] -= extra;
        a[i] += extra;
    }

    REP(i, n) {
        assert(a[i] == goal);
    }

    cout << res.size() << endl;
    REP(i, res.size()) {
        join(res[i], " ");
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    cin >> tt;

#ifdef DEBUG
    // for (int t = 1; t <= tt || cin.rdbuf()->in_avail(); t++) {
    //     // cout << "Case #" << t << ": ";
    //     solve();
    // }

    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#else
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#endif

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#ifdef DEBUG
    #define endl endl
#else
    #define endl "\n"
#endif

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())
#define UNIQUE(v) \
    SORT(v);      \
    v.resize(distance(v.begin(), unique(v.begin(), v.end())))

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << endl;
}

const ll md = 1e9 + 7;
ll MOD(ll x) {
    ll r = x % md;
    if (r < 0) {
        r += md;
    }
    return r;
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF DBL_MAX
// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 1e18
#define MINF -INF

void solve() {
    ll n;
    cin >> n;
    ll res = 0;

    // cout << fixed << setprecision(6);
    cout << res << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;

#ifdef DEBUG
    // for (int t = 1; t <= tt || cin.rdbuf()->in_avail(); t++) {
    //     // cout << "Case #" << t << ": ";
    //     solve();
    // }

    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#else
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#endif

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#ifdef DEBUG
#define endl endl
#else
#define endl "\n"
#endif

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())
#define UNIQUE(v) \
    SORT(v);      \
    v.resize(distance(v.begin(), unique(v.begin(), v.end())))

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << endl;
}

const ll md = 1e9 + 7;
ll MOD(ll x) {
    ll r = x % md;
    if (r < 0) {
        r += md;
    }
    return r;
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF DBL_MAX
// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 1e18
#define MINF -INF

void solve() {
    ll n;
    cin >> n;
    vector<vll> res;
    vll a(n);
    REP(i, n) {
        cin >> a[i];
    }

    ll sm = accumulate(a.begin(), a.end(), 0);
    if (sm % n != 0) {
        cout << -1 << endl;
        return;
    }

    ll goal = sm / n;

    FOR(i, 1, n) {
        if (a[i] >= i + 1) {
            ll x = a[i] / (i + 1);
            if (x == 0)
                continue;
            res.push_back({i + 1, 1, x});
            ll reduced = x * (i + 1);
            a[i] -= reduced;
            a[0] += reduced;
        }
    }

    vector<pll> leftIdx;
    FOR(i, 1, n) {
        if (a[i] > 0) {
            ll left = i + 1 - a[i];
            leftIdx.push_back({left, i});
        }
    }
    SORT(leftIdx);
    for (auto& pr : leftIdx) {
        ll left = pr.first;
        ll i = pr.second;
        res.push_back({1, i + 1, left});
        a[0] -= left;
        assert(a[0] >= 0);
        a[i] += left;
        res.push_back({i + 1, 1, 1});
        a[0] += a[i];
        a[i] = 0;
    }

    FOR(i, 1, n) {
        assert(a[i] <= goal);
        ll extra = goal - a[i];
        if (extra == 0)
            continue;
        res.push_back({1, i + 1, extra});
        a[0] -= extra;
        a[i] += extra;
    }

    REP(i, n) {
        assert(a[i] == goal);
    }

    cout << res.size() << endl;
    REP(i, res.size()) {
        join(res[i], " ");
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    cin >> tt;

#ifdef DEBUG
    // for (int t = 1; t <= tt || cin.rdbuf()->in_avail(); t++) {
    //     // cout << "Case #" << t << ": ";
    //     solve();
    // }

    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#else
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#endif

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#ifdef DEBUG
#define endl endl
#else
#define endl "\n"
#endif

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())
#define UNIQUE(v) \
    SORT(v);      \
    v.resize(distance(v.begin(), unique(v.begin(), v.end())))

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << endl;
}

const ll md = 1e9 + 7;
ll MOD(ll x) {
    ll r = x % md;
    if (r < 0) {
        r += md;
    }
    return r;
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF DBL_MAX
// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 1e18
#define MINF -INF

void solve() {
    ll n;
    cin >> n;
    vector<vll> res;
    vll a(n);
    REP(i, n) {
        cin >> a[i];
    }

    ll sm = accumulate(a.begin(), a.end(), 0);
    if (sm % n != 0) {
        cout << -1 << endl;
        return;
    }

    ll goal = sm / n;

    FOR(i, 1, n) {
        ll rem = a[i] % (i + 1);
        ll need = (i + 1 - rem) % (i + 1);
        res.push_back({1, i + 1, need});
        a[i] += need;
        res.push_back({i + 1, 1, a[i] / (i + 1)});
        a[0] += a[i];
        a[i] = 0;
    }

    FOR(i, 1, n) {
        res.push_back({1, i + 1, goal});
        a[0] -= goal;
        a[i] += goal;
    }

    FOR(i, 0, n) {
        assert(a[i] == goal);
    }

    cout << res.size() << endl;
    REP(i, res.size()) {
        join(res[i], " ");
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    cin >> tt;

#ifdef DEBUG
    // for (int t = 1; t <= tt || cin.rdbuf()->in_avail(); t++) {
    //     // cout << "Case #" << t << ": ";
    //     solve();
    // }

    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#else
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
#endif

    return 0;
}