#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define ms(x, y) memset(x, y, sizeof(x))
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const lld pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //--> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

const int MM = 1e5 + 5;
const int MX = 16;
int N, M, LCA[MM][MX+5], sz[MM], dep[MM], pre[MM], best[MM]; vector<vector<int>> adj; bool vis[MM];

int getCentroid(int v, int pa, int n) {
    for (int x : adj[v]) {
        if (x == pa || vis[x]) continue;
        if (sz[x] > n / 2) return getCentroid(x, v, n);
    }
    return v;
}

void init_centroid(int cur, int pa) {
    int siz = sz[cur];
    int c = getCentroid(cur, -1, siz);
    vis[c] = 1; pre[c] = pa;

    for (int x : adj[c]) {
        if (!vis[x]) {
            init_centroid(x, c);
        }
    }
}

void init() {
    for (int j = 1; j <= MX; j++) {
        for (int i = 1; i <= N; i++) {
            int par = LCA[i][j-1];
            if (par != -1) {
                LCA[i][j] = LCA[par][j-1];
            }
        }
    }
}

int lca(int a, int b) {
    if (dep[a] < dep[b]) swap(a, b); //dep[a] >= dep[b]
    int d = dep[a] - dep[b];
    while (d > 0) {
        int i = log2(d);
        a = LCA[a][i];
        d -= (1 << i);
    }
    if (a == b) return a;
    for (int i = MX; i >= 0; i--) {
        if (LCA[a][i] != -1 && LCA[b][i] != -1 && LCA[a][i] != LCA[b][i]) a = LCA[a][i], b = LCA[b][i];
    }
    return LCA[a][0];
}

void dfs0(int cur, int pa) {
    sz[cur] = 1; LCA[cur][0] = pa;
    for (int v : adj[cur]) {
        if (v != pa) {
            dep[v] = dep[cur] + 1;
            dfs0(v, cur);
            sz[cur] += sz[v];
        }
    }
}

void solve(int tc) {

    cin >> N >> M; adj = vector<vector<int> >(N+1, vector<int>()); ms(LCA, -1); ms(best, INF); ms(pre, -1);
    for (int i = 1, a, b; i < N; i++) {
        cin >> a >> b;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    dep[1] = 1; dfs0(1, -1); init(); init_centroid(1, -1);
    //1st node is red; update node 1
    for (int i = 1; i != -1; i = pre[i]) {
        int ancestor = lca(1, i);
        if (ancestor == -1) continue;
        int d = dep[1] + dep[i] - 2 * dep[ancestor];
        best[i] = min(best[i], d);
    }
    while (M--) {
        int t, v; cin >> t >> v;
        if (t == 1) {
            //update
            for (int i = v; i != -1; i = pre[i]) {
                int ancestor = lca(v, i);
                if (ancestor == -1) continue;
                int d = dep[v] + dep[i] - 2 * dep[ancestor];
                best[i] = min(best[i], d);
            }
        } else if (t == 2) {
            //query
            int ans = INF;
            for (int i = v; i != -1; i = pre[i]) {
                int ancestor = lca(v, i);
                if (ancestor == -1) continue;
                int d = dep[v] + dep[i] - 2 * dep[ancestor];
                ans = min(ans, best[i] + d);
            }
            cout << ans << nl;
        }
    }

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 1; t <= tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define ms(x, y) memset(x, y, sizeof(x))
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const lld pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //--> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

const int MM = 1e5 + 5;
const int MX = 16;
int N, M, LCA[MM][MX+5], sz[MM], dep[MM], pre[MM], best[MM]; vector<vector<int>> adj; bool vis[MM];

int getCentroid(int v, int pa, int n) {
    for (int x : adj[v]) {
        if (x == pa || vis[x]) continue;
        if (sz[x] > n / 2) return getCentroid(x, v, n);
    }
    return v;
}

void init_centroid(int cur, int pa) {
    int siz = sz[cur];
    int c = getCentroid(cur, -1, siz);
    vis[c] = 1; pre[c] = pa;

    for (int x : adj[c]) {
        if (!vis[x]) {
            init_centroid(x, c);
        }
    }
}

void init() {
    for (int j = 1; j <= MX; j++) {
        for (int i = 1; i <= N; i++) {
            int par = LCA[i][j-1];
            if (par != -1) {
                LCA[i][j] = LCA[par][j-1];
            }
        }
    }
}

int lca(int a, int b) {
    if (dep[a] < dep[b]) swap(a, b); //dep[a] >= dep[b]
    int d = dep[a] - dep[b];
    while (d > 0) {
        int i = log2(d);
        a = LCA[a][i];
        d -= (1 << i);
    }
    if (a == b) return a;
    for (int i = MX; i >= 0; i--) {
        if (LCA[a][i] != -1 && LCA[b][i] != -1 && LCA[a][i] != LCA[b][i]) a = LCA[a][i], b = LCA[b][i];
    }
    return LCA[a][0];
}

void dfs0(int cur, int pa) {
    sz[cur] = 1; LCA[cur][0] = pa;
    for (int v : adj[cur]) {
        if (v != pa) {
            dep[v] = dep[cur] + 1;
            dfs0(v, cur);
            sz[cur] += sz[v];
        }
    }
}

void solve(int tc) {

    cin >> N >> M; adj = vector<vector<int> >(N+1, vector<int>());
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= MX; j++) LCA[i][j] = -1; }
    for (int i = 1; i <= N; i++) { best[i] = 2e5; pre[i] = -1; }
    for (int i = 1, a, b; i < N; i++) {
        cin >> a >> b;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    dep[1] = 1; dfs0(1, -1); init(); init_centroid(1, -1);
    //1st node is red; update node 1
    for (int i = 1; i != -1; i = pre[i]) {
        int ancestor = lca(1, i);
        if (ancestor == -1) continue;
        int d = dep[1] + dep[i] - 2 * dep[ancestor];
        best[i] = min(best[i], d);
    }
    while (M--) {
        int t, v; cin >> t >> v;
        if (t == 1) {
            //update
            for (int i = v; i != -1; i = pre[i]) {
                int ancestor = lca(v, i);
                if (ancestor == -1) continue;
                int d = dep[v] + dep[i] - 2 * dep[ancestor];
                best[i] = min(best[i], d);
            }
        } else if (t == 2) {
            //query
            int ans = INF;
            for (int i = v; i != -1; i = pre[i]) {
                int ancestor = lca(v, i);
                if (ancestor == -1) continue;
                int d = dep[v] + dep[i] - 2 * dep[ancestor];
                ans = min(ans, best[i] + d);
            }
            cout << ans << nl;
        }
    }

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 1; t <= tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <utility>
#include <iterator>
#include <set>
#include <map>
#include <bitset>
#include <queue>

using namespace std;

#define X first
#define Y second
#define pb push_back
#define INF 1000000000
#define EPS 0.0000001
#define F(i,a,b) for(int (i) = (a) ; (i)<=(b) ; (i)++ )
#define error(a) cerr << #a << " = " << a << '\n';

typedef long long ll;
const int MAX_N= 100000 + 100 , MAX_LOG = log2(MAX_N) , S = sqrt(MAX_N);

vector<int> adj[MAX_N] , temp ;
int n , m , ans[MAX_N] , red[MAX_N];

//************** LCA
int par[MAX_N][MAX_LOG] , h[MAX_N];
void dfs_LCA(int v , int pr = -1){
	par[v][0] = pr;
	if(pr + 1) h[v] = h[pr] + 1;
	F(i , 1 , MAX_LOG - 1){
		if(par[v][i-1] + 1){
			par[v][i] = par[par[v][i-1]][i-1];
		}
	}
	for(int x : adj[v]){
		if(x != pr) dfs_LCA(x , v);
	}
}
inline int LCA(int u , int v){
	if(h[u] > h[v]) swap(u , v);
	for(int i = MAX_LOG-1 ; i>=0 ; --i){
		if(par[v][i] + 1){
			if(h[par[v][i]] >= h[u]) v = par[v][i];
		}
	}
	if(u == v) return u;
	for(int i = MAX_LOG - 1 ; i >=0 ; i--){
		if(par[v][i] != par[u][i]) u = par[u][i] , v = par[v][i];
	}
	return par[v][0];
}
inline int distance(int u , int v){int x = LCA(u , v) ; return abs(h[x] - h[u]) + abs(h[x] - h[v]);}
//******************

inline void bfs(){
	bool mark[MAX_N] = {};
	queue<pair<pair<int , int> , int> > q; // {{x , par } , dis}
	F(i , 1 , n) if(red[i]) q.push({{i , -1} , 0}) , mark[i] = 1;
	temp.clear();

	while(!q.empty()){
		auto v = q.front();
		q.pop();
		ans[v.X.X] = min(ans[v.X.X] , v.Y);
		for(int u : adj[v.X.X]){
			if(u != v.X.Y && !mark[u]) q.push({{u , v.X.X} , v.Y + 1});
		}
		mark[v.X.X] = 1;
	}

}

inline int ans_temp(int v){
	int ret = INF;
	for(int x : temp) ret = min(ret , distance(x , v));
	return ret;
}

main(){
	ios::sync_with_stdio(false);

	int u , v , t;
	temp.pb(1);
	red[1] = 1;
	fill(ans , ans + MAX_N , INF);

	F(i , 0 , MAX_N - 1) F(j , 0 , MAX_LOG - 1) par[i][j] = -1;

	scanf("%d%d",&n,&m);
	F(i , 1 , n-1){
		scanf("%d%d",&u,&v);
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dfs_LCA(1);

	while(m--){
		scanf("%d%d",&t,&v);
		if(t == 1){ // blue
			temp.pb(v);
			red[v] = 1;
		}
		else{
			if(temp.size() > S) bfs();
			int ansi = min(ans[v] , ans_temp(v));
			printf("%d\n",ansi);
		}
	}

	return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <utility>
#include <iterator>
#include <set>
#include <map>
#include <bitset>
#include <queue>

using namespace std;

#define X first
#define Y second
#define pb push_back
#define INF 1000000000
#define EPS 0.0000001
#define F(i,a,b) for(int (i) = (a) ; (i)<=(b) ; (i)++ )
#define error(a) cerr << #a << " = " << a << '\n';

typedef long long ll;
const int MAX_N= 100000 + 100 , MAX_LOG = log2(MAX_N) , S = sqrt(MAX_N);

vector<int> adj[MAX_N] , temp ;
int n , m , ans[MAX_N];

//************** LCA
int par[MAX_N][MAX_LOG] , h[MAX_N];
void dfs_LCA(int v , int pr = -1){
	par[v][0] = pr;
	if(pr + 1) h[v] = h[pr] + 1;
	F(i , 1 , MAX_LOG - 1){
		if(par[v][i-1] + 1){
			par[v][i] = par[par[v][i-1]][i-1];
		}
	}
	for(int x : adj[v]){
		if(x != pr) dfs_LCA(x , v);
	}
}
inline int LCA(int u , int v){
	if(h[u] > h[v]) swap(u , v);
	for(int i = MAX_LOG-1 ; i>=0 ; --i){
		if(par[v][i] + 1){
			if(h[par[v][i]] >= h[u]) v = par[v][i];
		}
	}
	if(u == v) return u;
	for(int i = MAX_LOG - 1 ; i >=0 ; i--){
		if(par[v][i] != par[u][i]) u = par[u][i] , v = par[v][i];
	}
	return par[v][0];
}
inline int distance(int u , int v){int x = LCA(u , v) ; return abs(h[x] - h[u]) + abs(h[x] - h[v]);}
//******************

inline void bfs(){
	bool mark[MAX_N] = {};
	queue<pair<pair<int , int> , int> > q; // {{x , par } , dis}
	for(int x : temp) q.push({{x , -1} , 0});
	temp.clear();

	while(!q.empty()){
		auto v = q.front();
		q.pop();
		ans[v.X.X] = min(ans[v.X.X] , v.Y);
		for(int u : adj[v.X.X]){
			if(u != v.X.Y && !mark[u]) q.push({{u , v.X.X} , v.Y + 1});
		}
		mark[v.X.X] = 1;
	}

}

inline int ans_temp(int v){
	int ret = INF;
	for(int x : temp) ret = min(ret , distance(x , v));
	return ret;
}

main(){
	ios::sync_with_stdio(false);

	int u , v , t;
	temp.pb(1);
	fill(ans , ans + MAX_N , INF);

	F(i , 0 , MAX_N - 1) F(j , 0 , MAX_LOG - 1) par[i][j] = -1;

	scanf("%d%d",&n,&m);
	F(i , 1 , n-1){
		scanf("%d%d",&u,&v);
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dfs_LCA(1);

	while(m--){
		scanf("%d%d",&t,&v);
		if(t == 1){ // blue
			temp.pb(v);
		}
		else{
			if(temp.size() > S) bfs();
			int ansi = min(ans[v] , ans_temp(v));
			printf("%d\n",ansi);
		}
	}

	return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <utility>
#include <iterator>
#include <set>
#include <map>
#include <bitset>
#include <queue>

using namespace std;

#define X first
#define Y second
#define pb push_back
#define INF 1000000000
#define EPS 0.0000001
#define F(i,a,b) for(int (i) = (a) ; (i)<=(b) ; (i)++ )
#define error(a) cerr << #a << " = " << a << '\n';

typedef long long ll;
const int MAX_N= 100000 + 100 , MAX_LOG = log2(MAX_N) , S = sqrt(MAX_N);

vector<int> adj[MAX_N] , temp ;
int n , m , ans[MAX_N];

//************** LCA
int par[MAX_N][MAX_LOG] , h[MAX_N];
void dfs_LCA(int v , int pr = -1){
	par[v][0] = pr;
	if(pr + 1) h[v] = h[pr] + 1;
	F(i , 1 , MAX_LOG - 1){
		if(par[v][i-1] + 1){
			par[v][i] = par[par[v][i-1]][i-1];
		}
	}
	for(int x : adj[v]){
		if(x != pr) dfs_LCA(x , v);
	}
}
inline int LCA(int u , int v){
	if(h[u] > h[v]) swap(u , v);
	for(int i = MAX_LOG-1 ; i>=0 ; --i){
		if(par[v][i] + 1){
			if(h[par[v][i]] >= h[u]) v = par[v][i];
		}
	}
	if(u == v) return u;
	for(int i = MAX_LOG - 1 ; i >=0 ; i--){
		if(par[v][i] != par[u][i]) u = par[u][i] , v = par[v][i];
	}
	return par[v][0];
}
inline int distance(int u , int v){int x = LCA(u , v) ; return abs(h[x] - h[u]) + abs(h[x] - h[v]);}
//******************

main(){
	ios::sync_with_stdio(false);

	int u , v , t;
	temp.pb(1);
	fill(ans , ans + MAX_N , INF);

	F(i , 0 , MAX_N - 1) F(j , 0 , MAX_LOG - 1) par[i][j] = -1;

	scanf("%d%d",&n,&m);
	F(i , 1 , n-1){
		scanf("%d%d",&u,&v);
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dfs_LCA(1);

	while(m--){
		scanf("%d%d",&t,&v);
		if(t == 1){ // blue
			temp.pb(v);
			if(temp.size() > S){ // bfs
					bool mark[MAX_N] = {};
					queue<pair<pair<int , int> , int> > q; // {{x , par } , dis}
					for(int x : temp) q.push({{x , -1} , 0});
					temp.clear();

					while(!q.empty()){
						auto v = q.front();
						q.pop();
						ans[v.X.X] = min(ans[v.X.X] , v.Y);
						for(int u : adj[v.X.X]){
							if(u != v.X.Y && !mark[u]) q.push({{u , v.X.X} , v.Y + 1});
					}
					mark[v.X.X] = 1;
					}
			}
		}
		else{
			int ansi = ans[v];
			for(int x : temp) ret = min(ansi, distance(x , v));
			printf("%d\n",ansi);
		}
	}

	return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <utility>
#include <iterator>
#include <set>
#include <map>
#include <bitset>
#include <queue>

using namespace std;

#define X first
#define Y second
#define pb push_back
#define INF 1000000000
#define EPS 0.0000001
#define F(i,a,b) for(int (i) = (a) ; (i)<=(b) ; (i)++ )
#define error(a) cerr << #a << " = " << a << '\n';

typedef long long ll;
const int MAX_N= 100000 + 100 , MAX_LOG = log2(MAX_N) , S = sqrt(MAX_N);

vector<int> adj[MAX_N] , temp ;
int n , m , ans[MAX_N];

//************** LCA
int par[MAX_N][MAX_LOG] , h[MAX_N];
void dfs_LCA(int v , int pr = -1){
	par[v][0] = pr;
	if(pr + 1) h[v] = h[pr] + 1;
	F(i , 1 , MAX_LOG - 1){
		if(par[v][i-1] + 1){
			par[v][i] = par[par[v][i-1]][i-1];
		}
	}
	for(int x : adj[v]){
		if(x != pr) dfs_LCA(x , v);
	}
}
inline int LCA(int u , int v){
	if(h[u] > h[v]) swap(u , v);
	for(int i = MAX_LOG-1 ; i>=0 ; --i){
		if(par[v][i] + 1){
			if(h[par[v][i]] >= h[u]) v = par[v][i];
		}
	}
	if(u == v) return u;
	for(int i = MAX_LOG - 1 ; i >=0 ; i--){
		if(par[v][i] != par[u][i]) u = par[u][i] , v = par[v][i];
	}
	return par[v][0];
}
inline int distance(int u , int v){int x = LCA(u , v) ; return abs(h[x] - h[u]) + abs(h[x] - h[v]);}
//******************

main(){
	ios::sync_with_stdio(false);

	int u , v , t;
	temp.pb(1);
	fill(ans , ans + MAX_N , INF);

	F(i , 0 , MAX_N - 1) F(j , 0 , MAX_LOG - 1) par[i][j] = -1;

	scanf("%d%d",&n,&m);
	F(i , 1 , n-1){
		scanf("%d%d",&u,&v);
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dfs_LCA(1);

	while(m--){
		scanf("%d%d",&t,&v);
		if(t == 1){ // blue
			temp.pb(v);
			if(temp.size() > S){ // bfs
					bool mark[MAX_N] = {};
					queue<pair<pair<int , int> , int> > q; // {{x , par } , dis}
					for(int x : temp) q.push({{x , -1} , 0});
					temp.clear();

					while(!q.empty()){
						auto v = q.front();
						q.pop();
						ans[v.X.X] = min(ans[v.X.X] , v.Y);
						for(int u : adj[v.X.X]){
							if(u != v.X.Y && !mark[u]) q.push({{u , v.X.X} , v.Y + 1});
					}
					mark[v.X.X] = 1;
					}
			}
		}
		else{
			int ansi = ans[v];
			for(int x : temp) ansi = min(ansi, distance(x , v));
			printf("%d\n",ansi);
		}
	}

	return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <utility>
#include <iterator>
#include <set>
#include <map>
#include <bitset>
#include <queue>

using namespace std;

#define X first
#define Y second
#define pb push_back
#define INF 1000000000
#define EPS 0.0000001
#define F(i,a,b) for(int (i) = (a) ; (i)<=(b) ; (i)++ )
#define error(a) cerr << #a << " = " << a << '\n';

typedef long long ll;
const int MAX_N= 100000 + 100 , MAX_LOG = log2(MAX_N) , S = sqrt(MAX_N);

vector<int> adj[MAX_N] , temp ;
int n , m , ans[MAX_N];

//************** LCA
int par[MAX_N][MAX_LOG] , h[MAX_N];
void dfs_LCA(int v , int pr = -1){
	par[v][0] = pr;
	if(pr + 1) h[v] = h[pr] + 1;
	F(i , 1 , MAX_LOG - 1){
		if(par[v][i-1] + 1){
			par[v][i] = par[par[v][i-1]][i-1];
		}
	}
	for(int x : adj[v]){
		if(x != pr) dfs_LCA(x , v);
	}
}
inline int LCA(int u , int v){
	if(h[u] > h[v]) swap(u , v);
	for(int i = MAX_LOG-1 ; i>=0 ; --i){
		if(par[v][i] + 1){
			if(h[par[v][i]] >= h[u]) v = par[v][i];
		}
	}
	if(u == v) return u;
	for(int i = MAX_LOG - 1 ; i >=0 ; i--){
		if(par[v][i] != par[u][i]) u = par[u][i] , v = par[v][i];
	}
	return par[v][0];
}
inline int distance(int u , int v){int x = LCA(u , v) ; return abs(h[x] - h[u]) + abs(h[x] - h[v]);}
//******************

inline void bfs(){
	bool mark[MAX_N] = {};
	queue<pair<pair<int , int> , int> > q; // {{x , par } , dis}
	for(int x : temp) q.push({{x , -1} , 0});
	temp.clear();

	while(!q.empty()){
		auto v = q.front();
		q.pop();
		ans[v.X.X] = min(ans[v.X.X] , v.Y);
		for(int u : adj[v.X.X]){
			if(u != v.X.Y && !mark[u]) q.push({{u , v.X.X} , v.Y + 1});
		}
		mark[v.X.X] = 1;
	}

}

inline int ans_temp(int v){
	int ret = INF;
	for(int x : temp) ret = min(ret , distance(x , v));
	return ret;
}

main(){
	ios::sync_with_stdio(false);

	int u , v , t;
	temp.pb(1);
	fill(ans , ans + MAX_N , INF);

	F(i , 0 , MAX_N - 1) F(j , 0 , MAX_LOG - 1) par[i][j] = -1;

	scanf("%d%d",&n,&m);
	F(i , 1 , n-1){
		scanf("%d%d",&u,&v);
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dfs_LCA(1);

	while(m--){
		scanf("%d%d",&t,&v);
		if(t == 1){ // blue
			temp.pb(v);
			if(temp.size() > S) bfs();
		}
		else{
			int ansi = min(ans[v] , ans_temp(v));
			printf("%d\n",ansi);
		}
	}

	return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <utility>
#include <iterator>
#include <set>
#include <map>
#include <bitset>
#include <queue>

using namespace std;

#define X first
#define Y second
#define pb push_back
#define INF 1000000000
#define EPS 0.0000001
#define F(i,a,b) for(int (i) = (a) ; (i)<=(b) ; (i)++ )
#define error(a) cerr << #a << " = " << a << '\n';

typedef long long ll;
const int MAX_N= 100000 + 100 , MAX_LOG = log2(MAX_N) , S = sqrt(MAX_N);

vector<int> adj[MAX_N] , temp ;
int n , m , ans[MAX_N] , red[MAX_N];

//************** LCA
int par[MAX_N][MAX_LOG] , h[MAX_N];
void dfs_LCA(int v , int pr = -1){
	par[v][0] = pr;
	if(pr + 1) h[v] = h[pr] + 1;
	F(i , 1 , MAX_LOG - 1){
		if(par[v][i-1] + 1){
			par[v][i] = par[par[v][i-1]][i-1];
		}
	}
	for(int x : adj[v]){
		if(x != pr) dfs_LCA(x , v);
	}
}
inline int LCA(int u , int v){
	if(h[u] > h[v]) swap(u , v);
	for(int i = MAX_LOG-1 ; i>=0 ; --i){
		if(par[v][i] + 1){
			if(h[par[v][i]] >= h[u]) v = par[v][i];
		}
	}
	if(u == v) return u;
	for(int i = MAX_LOG - 1 ; i >=0 ; i--){
		if(par[v][i] != par[u][i]) u = par[u][i] , v = par[v][i];
	}
	return par[v][0];
}
inline int distance(int u , int v){int x = LCA(u , v) ; return abs(h[x] - h[u]) + abs(h[x] - h[v]);}
//******************

inline void bfs(){
	bool mark[MAX_N] = {};
	queue<pair<pair<int , int> , int> > q; // {{x , par } , dis}
	F(i , 1 , n) if(red[i]) q.push({{i , -1} , 0}) , mark[i] = 1;
	temp.clear();

	while(!q.empty()){
		auto v = q.front();
		q.pop();
		ans[v.X.X] = min(ans[v.X.X] , v.Y);
		for(int u : adj[v.X.X]){
			if(u != v.X.Y && !mark[u]) q.push({{u , v.X.X} , v.Y + 1});
		}
		mark[v.X.X] = 1;
	}

}

inline int ans_temp(int v){
	int ret = INF;
	for(int x : temp) ret = min(ret , distance(x , v));
	return ret;
}

main(){
	ios::sync_with_stdio(false);

	int u , v , t;
	temp.pb(1);
	fill(ans , ans + MAX_N , INF);

	F(i , 0 , MAX_N - 1) F(j , 0 , MAX_LOG - 1) par[i][j] = -1;

	scanf("%d%d",&n,&m);
	F(i , 1 , n-1){
		scanf("%d%d",&u,&v);
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dfs_LCA(1);

	while(m--){
		scanf("%d%d",&t,&v);
		if(t == 1){ // blue
			temp.pb(v);
			red[v] = 1;
		}
		else{
			if(temp.size() > S) bfs();
			int ansi = min(ans[v] , ans_temp(v));
			printf("%d\n",ansi);
		}
	}

	return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <utility>
#include <iterator>
#include <set>
#include <map>
#include <bitset>
#include <queue>

using namespace std;

#define X first
#define Y second
#define pb push_back
#define INF 1000000000
#define EPS 0.0000001
#define F(i,a,b) for(int (i) = (a) ; (i)<=(b) ; (i)++ )
#define error(a) cerr << #a << " = " << a << '\n';

typedef long long ll;
const int MAX_N= 100000 + 100 , MAX_LOG = log2(MAX_N) , S = sqrt(MAX_N);

vector<int> adj[MAX_N] , temp ;
int n , m , ans[MAX_N];

//************** LCA
int par[MAX_N][MAX_LOG] , h[MAX_N];
void dfs_LCA(int v , int pr = -1){
	par[v][0] = pr;
	if(pr + 1) h[v] = h[pr] + 1;
	F(i , 1 , MAX_LOG - 1){
		if(par[v][i-1] + 1){
			par[v][i] = par[par[v][i-1]][i-1];
		}
	}
	for(int x : adj[v]){
		if(x != pr) dfs_LCA(x , v);
	}
}
int LCA(int u , int v){
	if(h[u] > h[v]) swap(u , v);
	for(int i = MAX_LOG-1 ; i>=0 ; --i){
		if(par[v][i] + 1){
			if(h[par[v][i]] >= h[u]) v = par[v][i];
		}
	}
	if(u == v) return u;
	for(int i = MAX_LOG - 1 ; i >=0 ; i--){
		if(par[v][i] != par[u][i]) u = par[u][i] , v = par[v][i];
	}
	return par[v][0];
}
int distance(int u , int v){int x = LCA(u , v) ; return abs(h[x] - h[u]) + abs(h[x] - h[v]);}
//******************

void bfs(){
	bool mark[MAX_N] = {};
	queue<pair<pair<int , int> , int> > q; // {{x , par } , dis}
	for(int x : temp) q.push({{x , -1} , 0});
	temp.clear();

	while(!q.empty()){
		auto v = q.front();
		q.pop();
		ans[v.X.X] = min(ans[v.X.X] , v.Y);
		for(int u : adj[v.X.X]){
			if(u != v.X.Y && !mark[u]) q.push({{u , v.X.X} , v.Y + 1});
		}
		mark[v.X.X] = 1;
	}

}

int ans_temp(int v){
	int ret = INF;
	for(int x : temp) ret = min(ret , distance(x , v));
	return ret;
}

main(){
	ios::sync_with_stdio(false);

	int u , v , t;
	temp.pb(1);
	fill(ans , ans + MAX_N , INF);

	F(i , 0 , MAX_N - 1) F(j , 0 , MAX_LOG - 1) par[i][j] = -1;

	scanf("%d%d",&n,&m)
	F(i , 1 , n-1){
		scanf("%d%d",&u,&v)
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dfs_LCA(1);

	while(m--){
		scanf("%d%d",&t,&v);
		if(t == 1){ // blue
			temp.pb(v);
			if(temp.size() > S) bfs();
		}
		else{
			int ansi = min(ans[v] , ans_temp(v));
			printf("%d\n",ansi);
		}
	}

	return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <utility>
#include <iterator>
#include <set>
#include <map>
#include <bitset>
#include <queue>

using namespace std;

#define X first
#define Y second
#define pb push_back
#define INF 1000000000
#define EPS 0.0000001
#define F(i,a,b) for(int (i) = (a) ; (i)<=(b) ; (i)++ )
#define error(a) cerr << #a << " = " << a << '\n';

typedef long long ll;
const int MAX_N= 100000 + 100 , MAX_LOG = log2(MAX_N) , S = sqrt(MAX_N);

vector<int> adj[MAX_N] , temp ;
int n , m , ans[MAX_N];

//************** LCA
int par[MAX_N][MAX_LOG] , h[MAX_N];
void dfs_LCA(int v , int pr = -1){
	par[v][0] = pr;
	if(pr + 1) h[v] = h[pr] + 1;
	F(i , 1 , MAX_LOG - 1){
		if(par[v][i-1] + 1){
			par[v][i] = par[par[v][i-1]][i-1];
		}
	}
	for(int x : adj[v]){
		if(x != pr) dfs_LCA(x , v);
	}
}
int LCA(int u , int v){
	if(h[u] > h[v]) swap(u , v);
	for(int i = MAX_LOG-1 ; i>=0 ; --i){
		if(par[v][i] + 1){
			if(h[par[v][i]] >= h[u]) v = par[v][i];
		}
	}
	if(u == v) return u;
	for(int i = MAX_LOG - 1 ; i >=0 ; i--){
		if(par[v][i] != par[u][i]) u = par[u][i] , v = par[v][i];
	}
	return par[v][0];
}
int distance(int u , int v){int x = LCA(u , v) ; return abs(h[x] - h[u]) + abs(h[x] - h[v]);}
//******************

void bfs(){
	bool mark[MAX_N] = {};
	queue<pair<pair<int , int> , int> > q; // {{x , par } , dis}
	for(int x : temp) q.push({{x , -1} , 0});
	temp.clear();

	while(!q.empty()){
		auto v = q.front();
		q.pop();
		ans[v.X.X] = min(ans[v.X.X] , v.Y);
		for(int u : adj[v.X.X]){
			if(u != v.X.Y && !mark[u]) q.push({{u , v.X.X} , v.Y + 1});
		}
		mark[v.X.X] = 1;
	}

}

int ans_temp(int v){
	int ret = INF;
	for(int x : temp) ret = min(ret , distance(x , v));
	return ret;
}

main(){
	ios::sync_with_stdio(false);

	int u , v , t;
	temp.pb(1);
	fill(ans , ans + MAX_N , INF);

	F(i , 0 , MAX_N - 1) F(j , 0 , MAX_LOG - 1) par[i][j] = -1;

	scanf("%d%d",&n,&m);
	F(i , 1 , n-1){
		scanf("%d%d",&u,&v);
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dfs_LCA(1);

	while(m--){
		scanf("%d%d",&t,&v);
		if(t == 1){ // blue
			temp.pb(v);
			if(temp.size() > S) bfs();
		}
		else{
			int ansi = min(ans[v] , ans_temp(v));
			printf("%d\n",ansi);
		}
	}

	return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <utility>
#include <iterator>
#include <set>
#include <map>
#include <bitset>
#include <queue>

using namespace std;

#define X first
#define Y second
#define pb push_back
#define INF 1000000000
#define EPS 0.0000001
#define F(i,a,b) for(int (i) = (a) ; (i)<=(b) ; (i)++ )
#define error(a) cerr << #a << " = " << a << '\n';

typedef long long ll;
const int MAX_N= 100000 + 100 , MAX_LOG = log2(MAX_N) , S = sqrt(MAX_N);

vector<int> adj[MAX_N] , temp ;
int n , m , ans[MAX_N];

//************** LCA
int par[MAX_N][MAX_LOG] , h[MAX_N];
void dfs_LCA(int v , int pr = -1){
	par[v][0] = pr;
	if(pr + 1) h[v] = h[pr] + 1;
	F(i , 1 , MAX_LOG - 1){
		if(par[v][i-1] + 1){
			par[v][i] = par[par[v][i-1]][i-1];
		}
	}
	for(int x : adj[v]){
		if(x != pr) dfs_LCA(x , v);
	}
}
int LCA(int u , int v){
	if(h[u] > h[v]) swap(u , v);
	for(int i = MAX_LOG-1 ; i>=0 ; --i){
		if(par[v][i] + 1){
			if(h[par[v][i]] >= h[u]) v = par[v][i];
		}
	}
	if(u == v) return u;
	for(int i = MAX_LOG - 1 ; i >=0 ; i--){
		if(par[v][i] != par[u][i]) u = par[u][i] , v = par[v][i];
	}
	return par[v][0];
}
int distance(int u , int v){int x = LCA(u , v) ; return abs(h[x] - h[u]) + abs(h[x] - h[v]);}
//******************

void bfs(){
	bool mark[MAX_N] = {};
	queue<pair<pair<int , int> , int> > q; // {{x , par } , dis}
	for(int x : temp) q.push({{x , -1} , 0});
	temp.clear();

	while(!q.empty()){
		auto v = q.front();
		q.pop();
		ans[v.X.X] = min(ans[v.X.X] , v.Y);
		for(int u : adj[v.X.X]){
			if(u != v.X.Y && !mark[u]) q.push({{u , v.X.X} , v.Y + 1});
		}
		mark[v.X.X] = 1;
	}

}

int ans_temp(int v){
	int ret = INF;
	for(int x : temp) ret = min(ret , distance(x , v));
	return ret;
}

main(){
	ios::sync_with_stdio(false);

	int u , v , t;
	temp.pb(1);
	fill(ans , ans + MAX_N , INF);

	F(i , 0 , MAX_N - 1) F(j , 0 , MAX_LOG - 1) par[i][j] = -1;

	cin >> n >> m;
	F(i , 1 , n-1){
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dfs_LCA(1);

	while(m--){
		cin >> t >> v;
		if(t == 1){ // blue
			temp.pb(v);
			if(temp.size() > S) bfs();
		}
		else{
			int ansi = min(ans[v] , ans_temp(v));
			cout << ansi << endl;
		}
	}

	return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <utility>
#include <iterator>
#include <set>
#include <map>
#include <bitset>
#include <queue>

using namespace std;

#define X first
#define Y second
#define pb push_back
#define INF 1000000000
#define EPS 0.0000001
#define F(i,a,b) for(int (i) = (a) ; (i)<=(b) ; (i)++ )
#define error(a) cerr << #a << " = " << a << '\n';

typedef long long ll;
const int MAX_N= 100000 + 100 , MAX_LOG = log2(MAX_N) , S = sqrt(MAX_N);

vector<int> adj[MAX_N] , temp ;
int n , m , ans[MAX_N] , red[MAX_N];

//************** LCA
int par[MAX_N][MAX_LOG] , h[MAX_N];
void dfs_LCA(int v , int pr = -1){
	par[v][0] = pr;
	if(pr + 1) h[v] = h[pr] + 1;
	F(i , 1 , MAX_LOG - 1){
		if(par[v][i-1] + 1){
			par[v][i] = par[par[v][i-1]][i-1];
		}
	}
	for(int x : adj[v]){
		if(x != pr) dfs_LCA(x , v);
	}
}
inline int LCA(int u , int v){
	if(h[u] > h[v]) swap(u , v);
	for(int i = MAX_LOG-1 ; i>=0 ; --i){
		if(par[v][i] + 1){
			if(h[par[v][i]] >= h[u]) v = par[v][i];
		}
	}
	if(u == v) return u;
	for(int i = MAX_LOG - 1 ; i >=0 ; i--){
		if(par[v][i] != par[u][i]) u = par[u][i] , v = par[v][i];
	}
	return par[v][0];
}
inline int distance(int u , int v){int x = LCA(u , v) ; return abs(h[x] - h[u]) + abs(h[x] - h[v]);}
//******************

inline void bfs(){
	bool mark[MAX_N] = {};
	queue<pair<pair<int , int> , int> > q; // {{x , par } , dis}
	F(i , 1 , n) if(red[i]) q.push({{i , -1} , 0}) , mark[i] = 1;
	temp.clear();

	while(!q.empty()){
		auto v = q.front();
		q.pop();
		ans[v.X.X] = min(ans[v.X.X] , v.Y);
		mark[v.X.X] = 1;
		for(int u : adj[v.X.X]){
			if(u != v.X.Y && !mark[u]){
				mark[u] = 1;
				q.push({{u , v.X.X} , v.Y + 1});
			}
		}

	}

}

inline int ans_temp(int v){
	int ret = INF;
	for(int x : temp) ret = min(ret , distance(x , v));
	return ret;
}

main(){
	ios::sync_with_stdio(false);

	int u , v , t;
	temp.pb(1);
	red[1] = 1;
	fill(ans , ans + MAX_N , INF);

	F(i , 0 , MAX_N - 1) F(j , 0 , MAX_LOG - 1) par[i][j] = -1;

	scanf("%d%d",&n,&m);
	F(i , 1 , n-1){
		scanf("%d%d",&u,&v);
		adj[u].pb(v);
		adj[v].pb(u);
	}

	dfs_LCA(1);

	while(m--){
		scanf("%d%d",&t,&v);
		if(t == 1){ // blue
			temp.pb(v);
			red[v] = 1;
		}
		else{
			if(temp.size() > S) bfs();
			int ansi = min(ans[v] , ans_temp(v));
			printf("%d\n",ansi);
		}
	}

	return 0;
}


//package CP.Ladder11;

import java.io.*;
import java.util.*;
import java.util.stream.IntStream;

import static java.lang.Math.*;
import static java.util.Arrays.*;

@SuppressWarnings("ALL")
public class AXeniaAndDivisors {
    public static void main(String[] $) throws IOException {
        AXeniaAndDivisors o = new AXeniaAndDivisors();
        o.main();
        out.flush();
        out.close();
    }

    void main() throws IOException {
        int n = in.ri();
        int[] a = in.ria(n);
        int[] count = new int[8];
        for (int i = 0; i < a.length; i++) {
            count[a[i]]++;
        }
        if (count[5] == 0 && count[7] == 0 && count[2] >= count[4] && count[1] == count[4] + count[6] && count[2] + count[3] == count[4] + count[6]) {
            for (int i = 0; i < count[4]; i++) {
                out.prln("1 2 4");
            }
            count[2] -= count[4];
            for (int i = 0; i < count[2]; i++) {
                out.prln("1 2 6");
            }
            for (int i = 0; i < count[3]; i++) {
                out.prln("1 3 6");
            }
        } else out.prln(-1);
    }

    static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));
    static StringTokenizer input;
    static Random __rand = new Random();
    // constants
    static final int IBIG = 1000000007;
    static final int IMAX = 2147483647;
    static final int IMIN = -2147483648;
    static final long LMAX = 9223372036854775807L;
    static final long LMIN = -9223372036854775808L;

    //Fast Reader Class
    /*static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }*/

    //Input fxs
    static class in {
        // input
        static void r() throws IOException {
            input = new StringTokenizer(rline());
        }

        static int ri() throws IOException {
            return Integer.parseInt(rline());
        }

        static long rl() throws IOException {
            return Long.parseLong(rline());
        }

        static double rd() throws IOException {
            return Double.parseDouble(rline());
        }

        static int[] ria(int n) throws IOException {
            int[] a = new int[n];
            r();
            for (int i = 0; i < n; ++i) a[i] = ni();
            return a;
        }

        static int[] riam1(int n) throws IOException {
            int[] a = new int[n];
            r();
            for (int i = 0; i < n; ++i) a[i] = ni() - 1;
            return a;
        }

        static long[] ria1i(long n) throws IOException {
            long[] a = new long[(int) n + 1];
            r();
            for (int i = 1; i <= n; i++) a[i] = nl();
            return a;
        }

        static long[] rla(int n) throws IOException {
            long[] a = new long[n];
            r();
            for (int i = 0; i < n; ++i) a[i] = nl();
            return a;
        }

        static double[] rda(int n) throws IOException {
            double[] a = new double[n];
            r();
            for (int i = 0; i < n; ++i) a[i] = nd();
            return a;
        }

        static char[] rcha() throws IOException {
            return rline().toCharArray();
        }

        static ArrayList<Integer> riaa(int n) throws IOException {
            ArrayList<Integer> a = new ArrayList<>();
            r();
            for (int i = 0; i < n; i++) a.add(ni());
            return a;
        }

        static String rline() throws IOException {
            return __in.readLine();
        }

        static String n() {
            return input.nextToken();
        }

        static int rni() throws IOException {
            r();
            return ni();
        }

        static int ni() {
            return Integer.parseInt(n());
        }

        static long rnl() throws IOException {
            r();
            return nl();
        }

        static long nl() {
            return Long.parseLong(n());
        }

        static double rnd() throws IOException {
            r();
            return nd();
        }

        static double nd() {
            return Double.parseDouble(n());
        }

        static List<List<Integer>> rg(int n, int m) throws IOException {
            List<List<Integer>> g = GR.g(n);
            for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);
            return g;
        }

        static void rg(List<List<Integer>> g, int m) throws IOException {
            for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);
        }

        static List<List<Integer>> rdg(int n, int m) throws IOException {
            List<List<Integer>> g = GR.g(n);
            for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);
            return g;
        }

        static void rdg(List<List<Integer>> g, int m) throws IOException {
            for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);
        }

        static List<Set<Integer>> rsg(int n, int m) throws IOException {
            List<Set<Integer>> g = GR.sg(n);
            for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);
            return g;
        }

        static void rsg(List<Set<Integer>> g, int m) throws IOException {
            for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);
        }

        static List<Set<Integer>> rdsg(int n, int m) throws IOException {
            List<Set<Integer>> g = GR.sg(n);
            for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);
            return g;
        }

        static void rdsg(List<Set<Integer>> g, int m) throws IOException {
            for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);
        }

        static int[][] rim(int n, int m) throws IOException {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++) {
                in.r();
                for (int j = 0; j < m; j++) {
                    a[i][j] = in.ni();
                }
            }
            return a;
        }
    }

    //Output fxs
    static class out {
        // output
        static void pr(int i) {
            __out.print(i);
        }

        static void prln(int i) {
            __out.println(i);
        }

        static void pr(long l) {
            __out.print(l);
        }

        static void prln(long l) {
            __out.println(l);
        }

        static void pr(double d) {
            __out.print(d);
        }

        static void prln(double d) {
            __out.println(d);
        }

        static void pr(char c) {
            __out.print(c);
        }

        static void prln(char c) {
            __out.println(c);
        }

        static void pr(char[] s) {
            __out.print(new String(s));
        }

        static void prln(char[] s) {
            __out.println(new String(s));
        }

        static void pr(String s) {
            __out.print(s);
        }

        static void prln(String s) {
            __out.println(s);
        }

        static void pr(Object o) {
            __out.print(o);
        }

        static void prln(Object o) {
            __out.println(o);
        }

        static void prln() {
            __out.println();
        }

        static void pryes() {
            prln("yes");
        }

        static void pry() {
            prln("Yes");
        }

        static void prY() {
            prln("YES");
        }

        static void prno() {
            prln("no");
        }

        static void prn() {
            prln("No");
        }

        static void prN() {
            prln("NO");
        }

        static void pryesno(boolean b) {
            prln(b ? "yes" : "no");
        }

        ;

        static void pryn(boolean b) {
            prln(b ? "Yes" : "No");
        }

        static void prYN(boolean b) {
            prln(b ? "YES" : "NO");
        }

        static void prln(int... a) {
            for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;
            if (a.length > 0) prln(a[a.length - 1]);
            else prln();
        }

        static void prln(long... a) {
            for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;
            if (a.length > 0) prln(a[a.length - 1]);
            else prln();
        }

        static void prln(double... a) {
            for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;
            if (a.length > 0) prln(a[a.length - 1]);
            else prln();
        }

        static <T> void prln(Collection<T> c) {
            int n = c.size() - 1;
            Iterator<T> iter = c.iterator();
            for (int i = 0; i < n; pr(iter.next()), pr(' '), ++i) ;
            if (n >= 0) prln(iter.next());
            else prln();
        }

        static void h() {
            prln("hlfd");
            flush();
        }

        static void flush() {
            __out.flush();
        }

        static void close() {
            __out.close();
        }

        static void prM(int[][] a, int n, int m) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++)
                    out.pr(a[i][j] + " ");
                out.prln();
            }
        }
    }

    //Math fxs
    static class mathx {
        // math util
        static int minof(int a, int b, int c) {
            return min(a, min(b, c));
        }

        static int minof(int... x) {
            if (x.length == 1) return x[0];
            if (x.length == 2) return min(x[0], x[1]);
            if (x.length == 3) return min(x[0], min(x[1], x[2]));
            int min = x[0];
            for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i];
            return min;
        }

        static long minof(long a, long b, long c) {
            return min(a, min(b, c));
        }

        static long minof(long... x) {
            if (x.length == 1) return x[0];
            if (x.length == 2) return min(x[0], x[1]);
            if (x.length == 3) return min(x[0], min(x[1], x[2]));
            long min = x[0];
            for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i];
            return min;
        }

        static int maxof(int a, int b, int c) {
            return max(a, max(b, c));
        }

        static int maxof(int... x) {
            if (x.length == 1) return x[0];
            if (x.length == 2) return max(x[0], x[1]);
            if (x.length == 3) return max(x[0], max(x[1], x[2]));
            int max = x[0];
            for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i];
            return max;
        }

        static long maxof(long a, long b, long c) {
            return max(a, max(b, c));
        }

        static long maxof(long... x) {
            if (x.length == 1) return x[0];
            if (x.length == 2) return max(x[0], x[1]);
            if (x.length == 3) return max(x[0], max(x[1], x[2]));
            long max = x[0];
            for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i];
            return max;
        }

        static int powi(int a, int b) {
            if (a == 0) return 0;
            int ans = 1;
            while (b > 0) {
                if ((b & 1) > 0) ans *= a;
                a *= a;
                b >>= 1;
            }
            return ans;
        }

        static long powl(long a, int b) {
            if (a == 0) return 0;
            long ans = 1;
            while (b > 0) {
                if ((b & 1) > 0) ans *= a;
                a *= a;
                b >>= 1;
            }
            return ans;
        }

        static int fli(double d) {
            return (int) d;
        }

        static int cei(double d) {
            return (int) ceil(d);
        }

        static long fll(double d) {
            return (long) d;
        }

        static long cel(double d) {
            return (long) ceil(d);
        }

        static int gcd(int a, int b) {
            return b == 0 ? a : gcd(b, a % b);
        }

        static long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

        static int lcm(int a, int b) {
            return a * b / gcd(a, b);
        }

        static long lcm(long a, long b) {
            return a * b / gcd(a, b);
        }

        static int randInt(int min, int max) {
            return __rand.nextInt(max - min + 1) + min;
        }

        static long mix(long x) {
            x += 0x9e3779b97f4a7c15L;
            x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L;
            x = (x ^ (x >> 27)) * 0x94d049bb133111ebL;
            return x ^ (x >> 31);
        }
    }

    //Array fxs
    static class ARR {
        // array util
        static void reverse(int[] a) {
            for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
                int swap = a[i];
                a[i] = a[n - i - 1];
                a[n - i - 1] = swap;
            }
        }

        static void reverse(long[] a) {
            for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
                long swap = a[i];
                a[i] = a[n - i - 1];
                a[n - i - 1] = swap;
            }
        }

        static void reverse(double[] a) {
            for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
                double swap = a[i];
                a[i] = a[n - i - 1];
                a[n - i - 1] = swap;
            }
        }

        static void reverse(char[] a) {
            for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
                char swap = a[i];
                a[i] = a[n - i - 1];
                a[n - i - 1] = swap;
            }
        }

        static void shuffle(int[] a) {
            int n = a.length - 1;
            for (int i = 0; i < n; ++i) {
                int ind = mathx.randInt(i, n);
                int swap = a[i];
                a[i] = a[ind];
                a[ind] = swap;
            }
        }

        static void shuffle(long[] a) {
            int n = a.length - 1;
            for (int i = 0; i < n; ++i) {
                int ind = mathx.randInt(i, n);
                long swap = a[i];
                a[i] = a[ind];
                a[ind] = swap;
            }
        }

        static void shuffle(double[] a) {
            int n = a.length - 1;
            for (int i = 0; i < n; ++i) {
                int ind = mathx.randInt(i, n);
                double swap = a[i];
                a[i] = a[ind];
                a[ind] = swap;
            }
        }

        static void rsort(int[] a) {
            shuffle(a);
            sort(a);
        }

        static void rsort(long[] a) {
            shuffle(a);
            sort(a);
        }

        static void rsort(double[] a) {
            shuffle(a);
            sort(a);
        }

        static int[] copy(int[] a) {
            int[] ans = new int[a.length];
            System.arraycopy(a, 0, ans, 0, a.length);
            return ans;
        }

        static long[] copy(long[] a) {
            long[] ans = new long[a.length];
            System.arraycopy(a, 0, ans, 0, a.length);
            return ans;
        }

        static double[] copy(double[] a) {
            double[] ans = new double[a.length];
            System.arraycopy(a, 0, ans, 0, a.length);
            return ans;
        }

        static char[] copy(char[] a) {
            char[] ans = new char[a.length];
            System.arraycopy(a, 0, ans, 0, a.length);
            return ans;
        }
    }

    //Graph fxs
    static class GR {
        // graph util
        static List<List<Integer>> g(int n) {
            List<List<Integer>> g = new ArrayList<>();
            for (int i = 0; i < n; ++i) g.add(new ArrayList<>());
            return g;
        }

        static List<Set<Integer>> sg(int n) {
            List<Set<Integer>> g = new ArrayList<>();
            for (int i = 0; i < n; ++i) g.add(new HashSet<>());
            return g;
        }

        static void c(List<? extends Collection<Integer>> g, int u, int v) {
            g.get(u).add(v);
            g.get(v).add(u);
        }

        static void cto(List<? extends Collection<Integer>> g, int u, int v) {
            g.get(u).add(v);
        }

        static void dc(List<? extends Collection<Integer>> g, int u, int v) {
            g.get(u).remove(v);
            g.get(v).remove(u);
        }

        static void dcto(List<? extends Collection<Integer>> g, int u, int v) {
            g.get(u).remove(v);
        }
    }

    //Utilsx class
    static class utilX {
        static int[] subsetSum(int[] nums) {
            int M = IntStream.of(nums).sum();
            int[] m = new int[M + 10];
            for (int i = 0; i < M + 10; i++) m[i] = 0;
            m[0] = 1;
            for (int num : nums) {
                for (int j = M; j >= num; j--) {
                    m[j] |= m[j - num];
                }
            }
            return m;
        }

        static int LIS(int[] nums) {
            int[] m = new int[nums.length];
            for (int i = nums.length - 1; i >= 0; i--) {
                m[i] = 1;
                for (int j = i + 1; j < nums.length; j++) {
                    if (nums[j] > nums[i]) {
                        m[i] = max(m[i], m[j] + 1);
                    }
                }
            }
            int ans = 0;
            for (int i = 0; i < nums.length; i++) {
                ans = max(ans, m[i]);
            }
            return ans;
        }
    }

    //Pair Class
    static class Pair<F, S> {
        public final F first;
        public final S second;

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public boolean equals(Object o) {
            if (!(o instanceof Pair)) {
                return false;
            }
            Pair<?, ?> p = (Pair<?, ?>) o;
            return Objects.equals(p.first, first) && Objects.equals(p.second, second);
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

import java.util.Arrays;
import java.util.HashMap;
import java.util.ArrayList;

public class XeniaAndDivisors {
	static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String [] args) throws IOException
	{
		int arrLength = Integer.parseInt(reader.readLine());
		int [] integers = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();

		HashMap<Integer, Integer> freqMap = new HashMap<Integer, Integer> ();
		for (Integer x : integers)
		{
			if (x == 0 || x == 7 || x == 5)
			{
				System.out.println(-1);
				return;
			}
			else if (freqMap.containsKey(x))
			{
				freqMap.put(x, freqMap.get(x) + 1);
			}
			else
			{
				freqMap.put(x,1);
			}
		}

		ArrayList<Integer []> solution = new ArrayList<Integer []> ();
		while (freqMap.containsKey(1) && freqMap.containsKey(2) && freqMap.containsKey(4))
		{
			Integer [] temp = {1,2,4};
			solution.add(temp);
			freqMap.put(1, freqMap.get(1) - 1);
			freqMap.put(2, freqMap.get(2) - 1);
			freqMap.put(4, freqMap.get(4) - 1);

			if (freqMap.get(1) == 0)
			{
				freqMap.remove(1);
			}
			if (freqMap.get(2) == 0)
			{
				freqMap.remove(2);
			}
			if (freqMap.get(4) == 0)
			{
				freqMap.remove(4);
			}
		}

		while (freqMap.containsKey(1) && freqMap.containsKey(2) && freqMap.containsKey(6))
		{
			Integer [] temp = {1,2,6};
			solution.add(temp);
			freqMap.put(1, freqMap.get(1) - 1);
			freqMap.put(2, freqMap.get(2) - 1);
			freqMap.put(6, freqMap.get(6) - 1);

			if (freqMap.get(1) == 0)
			{
				freqMap.remove(1);
			}
			if (freqMap.get(2) == 0)
			{
				freqMap.remove(2);
			}
			if (freqMap.get(6) == 0)
			{
				freqMap.remove(6);
			}
		}

		while (freqMap.containsKey(1) && freqMap.containsKey(3) && freqMap.containsKey(6))
		{
			Integer [] temp = {1,3,6};
			solution.add(temp);
			freqMap.put(1, freqMap.get(1) - 1);
			freqMap.put(3, freqMap.get(3) - 1);
			freqMap.put(6, freqMap.get(6) - 1);

			if (freqMap.get(1) == 0)
			{
				freqMap.remove(1);
			}
			if (freqMap.get(3) == 0)
			{
				freqMap.remove(3);
			}
			if (freqMap.get(6) == 0)
			{
				freqMap.remove(6);
			}
		}

		if (solution.size() != arrLength / 3)
		{
			System.out.println(-1);
			return;
		}

		for (Integer [] sol : solution)
		{
			System.out.println(sol[0] + " " + sol[1] + " " + sol[2]);
		}

	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author unknown
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        AXeniaAndDivisors solver = new AXeniaAndDivisors();
        solver.solve(1, in, out);
        out.close();
    }

    static class AXeniaAndDivisors {
        int IINF = (int) 1e9 + 331;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int[] freq = new int[8];
            for (int i = 0; i < n; i++) {
                freq[in.nextInt()] += 1;
            }
            if (freq[7] > 0 || freq[5] > 0 || (freq[4] == 0 && freq[6] == 0)) {
                out.println(-1);
                return;
            }
            int[] triplets = new int[3];
            int min = IINF;
            if (freq[4] > 0) {
                min = _F.min(freq[1], freq[2], freq[4]);
                freq[1] -= min;
                freq[2] -= min;
                freq[4] -= min;
                triplets[0] += min;
                if (freq[4] > 0) {
                    out.println(-1);
                    return;
                }
            }
            if (freq[6] > 0) {
                min = _F.min(freq[1], freq[3], freq[6]);
                freq[1] -= min;
                freq[3] -= min;
                freq[6] -= min;
                triplets[2] += min;
                if (freq[6] > 0) {
                    min = _F.min(freq[1], freq[2], freq[6]);
                    freq[1] -= min;
                    freq[2] -= min;
                    freq[6] -= min;
                    triplets[1] += min;
                }
            }
            for (int i = 1; i <= 7; i++) {
                if (freq[i] > 0) {
                    out.println(-1);
                    return;
                }
            }
            for (int i = 0; i < triplets[0]; i++) {
                out.println(1, 2, 4);
            }
            for (int i = 0; i < triplets[1]; i++) {
                out.println(1, 2, 6);
            }
            for (int i = 0; i < triplets[2]; i++) {
                out.println(1, 3, 6);
            }
        }

    }

    static class _F {
        public static <T extends Comparable<T>> T min(T... list) {
            T candidate = list[0];
            for (T i : list) {
                if (candidate.compareTo(i) > 0) {
                    candidate = i;
                }
            }
            return candidate;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; ++i) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author unknown
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        AXeniaAndDivisors solver = new AXeniaAndDivisors();
        solver.solve(1, in, out);
        out.close();
    }

    static class AXeniaAndDivisors {
        int IINF = (int) 1e9 + 331;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int[] freq = new int[8];
            for (int i = 0; i < n; i++) {
                freq[in.nextInt()] += 1;
            }
            int[] triplets = new int[3];
            int min = IINF;
            min = _F.min(freq[1], freq[2], freq[4]);
            freq[1] -= min;
            freq[2] -= min;
            freq[4] -= min;
            triplets[0] += min;
            min = _F.min(freq[1], freq[3], freq[6]);
            freq[1] -= min;
            freq[3] -= min;
            freq[6] -= min;
            triplets[2] += min;
            min = _F.min(freq[1], freq[2], freq[6]);
            freq[1] -= min;
            freq[2] -= min;
            freq[6] -= min;
            triplets[1] += min;

            for (int i = 1; i <= 7; i++) {
                if (freq[i] > 0) {
                    out.println(-1);
                    return;
                }
            }
            for (int i = 0; i < triplets[0]; i++) {
                out.println(1, 2, 4);
            }
            for (int i = 0; i < triplets[1]; i++) {
                out.println(1, 2, 6);
            }
            for (int i = 0; i < triplets[2]; i++) {
                out.println(1, 3, 6);
            }
        }

    }

    static class _F {
        public static <T extends Comparable<T>> T min(T... list) {
            T candidate = list[0];
            for (T i : list) {
                if (candidate.compareTo(i) > 0) {
                    candidate = i;
                }
            }
            return candidate;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; ++i) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.util.*;
import java.io.*;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class CopyOfXenia_and_the_divisor
{
static Scanner sc=new Scanner(System.in);
static PrintWriter out=new PrintWriter(System.out);
static void pn(Object o)
{
out.println(o);
out.flush();

}
static void p(Object o)
{
out.print(o);
out.flush();
}
static void pni(Object o)
{
out.println(o);System.out.flush();
}

static int I() throws IOException
{
return sc.nextInt();
}
static long L()throws IOException
{
return sc.nextLong();
}
static double D()throws IOException
{
return sc.nextDouble();
}
static String S()throws IOException
{
return sc.nextLine();
    }
public static void process() throws IOException
{
     long n=L();
     int arr[]=new int[(int)n];
     for(int i=0;i<n;i++)
     {
         arr[i]=I();
     }

         int ctr[]=new int[10];
    for(int i=0;i<n;i++)
     {
         ctr[arr[i]]++;

        }

      int c=0;int k=(int)n/3;
      if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]>0 && ctr[6]>0 && ctr[4]<ctr[2] && ctr[2]-ctr[4]>=ctr[6])
      {
          c=(ctr[4])+(ctr[6]);
        }
     else
     if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]>0 && ctr[6]==0 && ctr[4]==ctr[2])
      {
             c=(ctr[2]);
          }
          else
          if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]==0 && ctr[6]>0 && ctr[6]==ctr[2])
      {
             c=(ctr[2]);
          }
     else
     if(ctr[2]<ctr[1] && ctr[3]<=(ctr[1]-ctr[2]) && ctr[4]>0 && ctr[6]>0 && ctr[4]<ctr[2] && ctr[2]-ctr[4]<ctr[6] && ctr[3]<=ctr[6])
      {
         c=(ctr[4])+((ctr[2]-ctr[4]))+(ctr[3]);

        }
     else
     if(ctr[2]==0 && ctr[3]==ctr[1] && ctr[4]==0 && ctr[6]>0 && ctr[3]==ctr[6])
      {
          c=ctr[3];
        }

     int l=ctr[2];
     if(c==k)
     {
      for(int i=ctr[2];i>0;i--)
     {
        if(ctr[4]>0)
        {
           pn("1 2 4");
           ctr[4]--;
           ctr[1]--;
           l--;
        }
        else
        if(i-ctr[4]>0 && ctr[6]>0)
        {
           pn("1 2 6");
           ctr[6]--;
           ctr[1]--;
           l--;
        }
     }
     for(int i=0;i<ctr[3];i++)
     {
         if(((l-ctr[4])-ctr[6]<0))
         {
           pn("1 3 6");

            }
        }
     }
    else
    {
        pn("-1");
    }
}

public static void main(String[] args)throws IOException
         {
            try
           {
               long T=L();
               while(T-->0)
               {
                   process();
                }

            }
            catch(Exception e)
            {
                return;
         }
    }
}


import java.util.*;
import java.io.*;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class CopyOfCopyOfXenia_and_the_divisor
{
static Scanner sc=new Scanner(System.in);
static PrintWriter out=new PrintWriter(System.out);
static void pn(Object o)
{
out.println(o);
out.flush();

}
static void p(Object o)
{
out.print(o);
out.flush();
}
static void pni(Object o)
{
out.println(o);System.out.flush();
}

static int I() throws IOException
{
return sc.nextInt();
}
static long L()throws IOException
{
return sc.nextLong();
}
static double D()throws IOException
{
return sc.nextDouble();
}
static String S()throws IOException
{
return sc.nextLine();
    }
public static void process() throws IOException
{
     long n=L();
     int arr[]=new int[(int)n];
     for(int i=0;i<n;i++)
     {
         arr[i]=I();
     }

         int ctr[]=new int[10];
    for(int i=0;i<n;i++)
     {
         ctr[arr[i]]++;

        }

      long c=0;long k=n/3;
      if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]>0 && ctr[6]>0 && ctr[4]<ctr[2] && ctr[2]-ctr[4]>=ctr[6])
      {
          c=(ctr[4])+(ctr[6]);
        }
     else
     if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]>0 && ctr[6]==0 && ctr[4]==ctr[2])
       {
             c=(ctr[2]);
          }
          else
          if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]==0 && ctr[6]>0 && ctr[6]==ctr[2])
      {
             c=(ctr[2]);
          }
     else
     if(ctr[2]<ctr[1] && ctr[3]<=(ctr[1]-ctr[2]) && ctr[4]>0 && ctr[6]>0 && ctr[4]<=ctr[2] && ctr[2]-ctr[4]<ctr[6] && ctr[3]<=ctr[6])
      {
         c=(ctr[4])+((ctr[2]-ctr[4]))+(ctr[3]);

        }
     else
     if(ctr[2]==0 && ctr[3]==ctr[1] && ctr[4]==0 && ctr[6]>0 && ctr[3]==ctr[6])
      {
          c=ctr[3];
        }

     int l=ctr[2];

     if(c==k)
     {
      for(int i=ctr[2];i>0;i--)
     {
        if(ctr[4]>0)
        {
           pn("1 2 4");
           ctr[4]--;
           ctr[1]--;
           l--;
        }
        else
        if(i-ctr[4]>0 && ctr[6]>0)
        {
           pn("1 2 6");
           ctr[6]--;
           ctr[1]--;
           l--;
        }
     }
     for(int i=0;i<ctr[3];i++)
     {
         if(((l-ctr[4])-ctr[6]<0))
         {
           pn("1 3 6");

            }
        }
     }
    else
    {
        pn("-1");
    }
}

public static void main(String[] args)throws IOException
         {
            try
           {

                   process();

            }
            catch(Exception e)
            {
                pn(e);
         }
    }
}


import java.util.*;
import java.io.*;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class CopyOfXenia_and_the_divisor
{
static Scanner sc=new Scanner(System.in);
static PrintWriter out=new PrintWriter(System.out);
static void pn(Object o)
{
out.println(o);
out.flush();

}
static void p(Object o)
{
out.print(o);
out.flush();
}
static void pni(Object o)
{
out.println(o);System.out.flush();
}

static int I() throws IOException
{
return sc.nextInt();
}
static long L()throws IOException
{
return sc.nextLong();
}
static double D()throws IOException
{
return sc.nextDouble();
}
static String S()throws IOException
{
return sc.nextLine();
    }
public static void process() throws IOException
{
     long n=L();
     int arr[]=new int[(int)n];
     for(int i=0;i<n;i++)
     {
         arr[i]=I();
     }

         int ctr[]=new int[10];
    for(int i=0;i<n;i++)
     {
         ctr[arr[i]]++;

        }

      int c=0;int k=(int)n/3;
      if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]>0 && ctr[6]>0 && ctr[4]<ctr[2] && ctr[2]-ctr[4]>=ctr[6])
      {
          c=(ctr[4])+(ctr[6]);
        }
     else
     if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]>0 && ctr[6]==0 && ctr[4]==ctr[2])
      {
             c=(ctr[2]);
          }
          else
          if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]==0 && ctr[6]>0 && ctr[6]==ctr[2])
      {
             c=(ctr[2]);
          }
     else
     if(ctr[2]<ctr[1] && ctr[3]<=(ctr[1]-ctr[2]) && ctr[4]>0 && ctr[6]>0 && ctr[4]<ctr[2] && ctr[2]-ctr[4]<ctr[6] && ctr[3]<=ctr[6])
      {
         c=(ctr[4])+((ctr[2]-ctr[4]))+(ctr[3]);

        }
     else
     if(ctr[2]==0 && ctr[3]==ctr[1] && ctr[4]==0 && ctr[6]>0 && ctr[3]==ctr[6])
      {
          c=ctr[3];
        }

     int l=ctr[2];
     if(c==k)
     {
      for(int i=ctr[2];i>0;i--)
     {
        if(ctr[4]>0)
        {
           pn("1 2 4");
           ctr[4]--;
           ctr[1]--;
           l--;
        }
        else
        if(i-ctr[4]>0 && ctr[6]>0)
        {
           pn("1 2 6");
           ctr[6]--;
           ctr[1]--;
           l--;
        }
     }
     for(int i=0;i<ctr[3];i++)
     {
         if(((l-ctr[4])-ctr[6]<0))
         {
           pn("1 3 6");

            }
        }
     }
    else
    {
        pn(-1);
    }
}

public static void main(String[] args)throws IOException
         {
            try
           {
               long T=L();
               while(T-->0)
               {
                   process();
                }

            }
            catch(Exception e)
            {
                return;
         }
    }
}


import java.util.*;
import java.io.*;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class CopyOfCopyOfXenia_and_the_divisor
{
static Scanner sc=new Scanner(System.in);
static PrintWriter out=new PrintWriter(System.out);
static void pn(Object o)
{
out.println(o);
out.flush();

}
static void p(Object o)
{
out.print(o);
out.flush();
}
static void pni(Object o)
{
out.println(o);System.out.flush();
}

static int I() throws IOException
{
return sc.nextInt();
}
static long L()throws IOException
{
return sc.nextLong();
}
static double D()throws IOException
{
return sc.nextDouble();
}
static String S()throws IOException
{
return sc.nextLine();
    }
public static void process() throws IOException
{
     long n=L();
     int arr[]=new int[(int)n];
     for(int i=0;i<n;i++)
     {
         arr[i]=I();
     }

         int ctr[]=new int[10];
    for(int i=0;i<n;i++)
     {
         ctr[arr[i]]++;

        }

      long c=0;long k=n/3;
      if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]>0 && ctr[6]>0 && ctr[4]<ctr[2] && ctr[2]-ctr[4]>=ctr[6])
      {
          c=(ctr[4])+(ctr[6]);
        }
     else
     if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]>0 && ctr[6]==0 && ctr[4]==ctr[2])
       {
             c=(ctr[2]);
          }
          else
          if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]==0 && ctr[6]>0 && ctr[6]==ctr[2])
      {
             c=(ctr[2]);
          }
     else
     if(ctr[2]<ctr[1] && ctr[3]<=(ctr[1]-ctr[2]) && ctr[4]>0 && ctr[6]>0 && ctr[4]<ctr[2] && ctr[2]-ctr[4]<ctr[6] && ctr[3]<=ctr[6])
      {
         c=(ctr[4])+((ctr[2]-ctr[4]))+(ctr[3]);

        }
     else
     if(ctr[2]==0 && ctr[3]==ctr[1] && ctr[4]==0 && ctr[6]>0 && ctr[3]==ctr[6])
      {
          c=ctr[3];
        }

     int l=ctr[2];

     if(c==k)
     {
      for(int i=ctr[2];i>0;i--)
     {
        if(ctr[4]>0)
        {
           pn("1 2 4");
           ctr[4]--;
           ctr[1]--;
           l--;
        }
        else
        if(i-ctr[4]>0 && ctr[6]>0)
        {
           pn("1 2 6");
           ctr[6]--;
           ctr[1]--;
           l--;
        }
     }
     for(int i=0;i<ctr[3];i++)
     {
         if(((l-ctr[4])-ctr[6]<0))
         {
           pn("1 3 6");

            }
        }
     }
    else
    {
        pn("-1");
    }
}

public static void main(String[] args)throws IOException
         {
            try
           {

                   process();

            }
            catch(Exception e)
            {
                pn(e);
         }
    }
}


import java.util.*;
import java.io.*;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class CopyOfCopyOfXenia_and_the_divisor
{
static Scanner sc=new Scanner(System.in);
static PrintWriter out=new PrintWriter(System.out);
static void pn(Object o)
{
out.println(o);
out.flush();

}
static void p(Object o)
{
out.print(o);
out.flush();
}
static void pni(Object o)
{
out.println(o);System.out.flush();
}

static int I() throws IOException
{
return sc.nextInt();
}
static long L()throws IOException
{
return sc.nextLong();
}
static double D()throws IOException
{
return sc.nextDouble();
}
static String S()throws IOException
{
return sc.nextLine();
    }
public static void process() throws IOException
{
     long n=L();
     int arr[]=new int[(int)n];
     for(int i=0;i<n;i++)
     {
         arr[i]=I();
     }

         int ctr[]=new int[10];
    for(int i=0;i<n;i++)
     {
         ctr[arr[i]]++;

        }

      long c=0;long k=n/3;
      if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]>0 && ctr[6]>0 && ctr[4]<ctr[2] && ctr[2]-ctr[4]>=ctr[6])
      {
          c=(ctr[4])+(ctr[6]);
        }
     else
     if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]>0 && ctr[6]==0 && ctr[4]==ctr[2])
       {
             c=(ctr[2]);
          }
          else
          if(ctr[2]==ctr[1] && ctr[3]==0 && ctr[4]==0 && ctr[6]>0 && ctr[6]==ctr[2])
      {
             c=(ctr[2]);
          }
     else
     if((ctr[3]+ctr[2])<=(ctr[1]) && ctr[4]>0 && ctr[6]>0 && ctr[4]<=ctr[2] && ctr[2]-ctr[4]<ctr[6] && ctr[3]<=ctr[6])
      {
         c=(ctr[4])+((ctr[2]-ctr[4]))+(ctr[3]);

        }
     else
     if((ctr[2]+ctr[3])==ctr[1] && ctr[4]==0 && ctr[6]>0 && ctr[2]+ctr[3]==ctr[6])
      {
         c=(ctr[4])+((ctr[2]-ctr[4]))+(ctr[3]);

        }
     else
     if(ctr[2]==0 && ctr[3]==ctr[1] && ctr[4]==0 && ctr[6]>0 && ctr[3]==ctr[6])
      {
          c=ctr[3];
        }

     int l=ctr[2];

     if(c==k)
     {
      for(int i=ctr[2];i>0;i--)
     {
        if(ctr[4]>0)
        {
           pn("1 2 4");
           ctr[4]--;
           ctr[1]--;
           l--;
        }
        else
        if(i-ctr[4]>0 && ctr[6]>0)
        {
           pn("1 2 6");
           ctr[6]--;
           ctr[1]--;
           l--;
        }
     }
     for(int i=0;i<ctr[3];i++)
     {
         if(((l-ctr[4])-ctr[6]<0))
         {
           pn("1 3 6");

            }
        }
     }
    else
    {
        pn("-1");
    }
}

public static void main(String[] args)throws IOException
         {
            try
           {

                   process();

            }
            catch(Exception e)
            {
                pn(e);
         }
    }
}


import java.util.*;

public class codef {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int n = s.nextInt();
        int[] a = new int[n];
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(s.nextInt());
        }
        Collections.sort(list);
        int k = 0;

        int flag = 0;
        for (int i = 0; i < list.size(); i++) {
            a[k] = list.get(i);
            list.remove(i);

            for (int j = 0; j < list.size(); j++) {
                if (list.get(j) != a[k] && list.get(j) % a[k] == 0) {
                    a[k + 1] = list.get(j);
                    list.remove(j);
                    k++;
                    flag = 1;
                    break;
                }
            }
            if (flag == 0) {
                break;
            } else {
                flag = 0;
            }
            for (int j = 0; j < list.size(); j++) {
                if (list.get(j) != a[k] && list.get(j) % a[k] == 0) {
                    a[k + 1] = list.get(j);
                    list.remove(j);
                    k++;
                    flag = 1;
                    break;
                }
            }
            if (flag == 0) {
                break;
            }
            k++;
            i = -1;
        }

        if (flag == 0 && k < a.length) {
            System.out.println(-1);
        } else {
            int count = 0;
            for (int i = 0; i < a.length; i++) {
                if (count == 3) {
                    System.out.println();
                    count = 0;
                }
                System.out.print(a[i] + " ");
                count++;
            }
        }
    }

}


import java.util.*;

public class codef {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int n=s.nextInt();
        int a[]=new int[8];
        for(int i=0;i<n;i++)
            a[s.nextInt()]++;

        boolean flag=true;
        StringBuilder sb=new StringBuilder();
        for(int i=0;i<n/3;i++)
        {
            int prev=1,count=0;
            for(int j=1;j<=7;j++)
            {
                if(a[j]>0 && j%prev==0)
                {
                    prev=j;
                    sb.append(j+" ");
                    a[j]--;
                    count++;
                }
            }
            if(count<3)
            {
                System.out.print("-1");
                flag=false;
                break;

            }
            sb.append("\n");

        }
        if(flag)
            System.out.println(sb);
    }

}


import java.io.*;
import java.util.*;

public class Main {

    // SOLVER
    static void solve() {
        // INPUT OUTPUT
        InputReader in = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        // SOLVE *************************************
        final int noOfElement = in.nextInt();
        Integer[] array = new Integer[noOfElement];
        for (int i = 0; i < noOfElement; i++) {
            array[i] = in.nextInt();
            if (array[i] == 5 || array[i] == 7) {
                pw.println(-1);
                pw.close();
                return;
            }
        }

        HashMap<Integer, Integer> countOfEachDigit = new HashMap<>();
        for (int i = 0; i < noOfElement; i++) {
            if (countOfEachDigit.containsKey(array[i])) {
                countOfEachDigit.put(array[i], countOfEachDigit.get(array[i]) + 1);
            } else {
                countOfEachDigit.put(array[i], 1);
            }
        }
        int countOfOne = 0;
        if (countOfEachDigit.containsKey(1)){
            countOfOne = countOfEachDigit.get(1);
        }
        if (countOfOne > 1) {
            pw.println(-1);
            pw.close();
            return;
        }
        int countOfTwo = 0;
        int countOfThree = 0;
        int countOfFour = 0;
        int countOfSix = 0;
        if (countOfEachDigit.containsKey(2)) {
            countOfTwo = countOfEachDigit.get(2);
        }
        if (countOfEachDigit.containsKey(3)) {
            countOfThree = countOfEachDigit.get(3);
        }
        if (countOfEachDigit.containsKey(4)) {
            countOfFour = countOfEachDigit.get(4);
        }
        if (countOfEachDigit.containsKey(6)) {
            countOfSix = countOfEachDigit.get(6);
        }
        StringBuilder result = new StringBuilder();

        if (countOfOne == (countOfFour + countOfSix)) {
            while (countOfTwo > 0 && (countOfFour > 0 || countOfSix > 0)) {
                if (countOfFour > 0) {
                    result.append(1).append(" ").append(2).append(" ").append(4).append('\n');
                    --countOfFour;
                } else if (countOfSix > 0) {
                    result.append(1).append(" ").append(2).append(" ").append(6).append('\n');
                    --countOfSix;
                }
                --countOfTwo;
            }
            while (countOfThree > 0 && (countOfFour > 0 || countOfSix > 0)) {
                if (countOfFour > 0) {
                    result.append(1).append(" ").append(3).append(" ").append(4).append('\n');
                    --countOfFour;
                } else if (countOfSix > 0) {
                    result.append(1).append(" ").append(3).append(" ").append(6).append('\n');
                    --countOfSix;
                }
                --countOfThree;
            }
            pw.println(result.toString().trim());

        } else {
            pw.println(-1);
        }
        // *************************************
        {
            pw.close();
        }
    }

    /**************************************************************************
     *************************************************************************/
    // DRIVER CODE
    public static void main(String[] args) {
        solve();
    }

    // FAST INPUT
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


import java.io.*;
import java.util.*;

public class Main {

    // SOLVER
    static void solve() {
        // INPUT OUTPUT
        InputReader in = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        // SOLVE *************************************
        final int noOfElement = in.nextInt();
        Integer[] array = new Integer[noOfElement];
        for (int i = 0; i < noOfElement; i++) {
            array[i] = in.nextInt();
            if (array[i] == 5 || array[i] == 7) {
                pw.println(-1);
                pw.close();
                return;
            }
        }

        HashMap<Integer, Integer> countOfEachDigit = new HashMap<>();
        for (int i = 0; i < noOfElement; i++) {
            if (countOfEachDigit.containsKey(array[i])) {
                countOfEachDigit.put(array[i], countOfEachDigit.get(array[i]) + 1);
            } else {
                countOfEachDigit.put(array[i], 1);
            }
        }
        int countOfOne = 0;
        if (countOfEachDigit.containsKey(1)){
            countOfOne = countOfEachDigit.get(1);
        }
        if (countOfOne < 2) {
            pw.println(-1);
            pw.close();
            return;
        }
        int countOfTwo = 0;
        int countOfThree = 0;
        int countOfFour = 0;
        int countOfSix = 0;
        if (countOfEachDigit.containsKey(2)) {
            countOfTwo = countOfEachDigit.get(2);
        }
        if (countOfEachDigit.containsKey(3)) {
            countOfThree = countOfEachDigit.get(3);
        }
        if (countOfEachDigit.containsKey(4)) {
            countOfFour = countOfEachDigit.get(4);
        }
        if (countOfEachDigit.containsKey(6)) {
            countOfSix = countOfEachDigit.get(6);
        }
        StringBuilder result = new StringBuilder();

        if (countOfOne == (countOfFour + countOfSix) && countOfThree <= countOfSix) {
            while (countOfTwo > 0 && (countOfFour > 0 || countOfSix > 0)) {
                if (countOfFour > 0) {
                    result.append(1).append(" ").append(2).append(" ").append(4).append('\n');
                    --countOfFour;
                } else if (countOfSix > 0) {
                    result.append(1).append(" ").append(2).append(" ").append(6).append('\n');
                    --countOfSix;
                }
                --countOfTwo;
            }
            while (countOfThree > 0 && (countOfFour > 0 || countOfSix > 0)) {
                if (countOfFour > 0) {
                    result.append(1).append(" ").append(3).append(" ").append(4).append('\n');
                    --countOfFour;
                } else if (countOfSix > 0) {
                    result.append(1).append(" ").append(3).append(" ").append(6).append('\n');
                    --countOfSix;
                }
                --countOfThree;
            }
            pw.println(result.toString().trim());

        } else {
            pw.println(-1);
        }
        // *************************************
        {
            pw.close();
        }
    }

    /**************************************************************************
     *************************************************************************/
    // DRIVER CODE
    public static void main(String[] args) {
        solve();
    }

    // FAST INPUT
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;

public class xeniaAndDivisors {
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n=sc.nextInt();
		int b[]=new int[n];
		int a[]=new int[8];
		StringBuilder stb=new StringBuilder();
		int flag=0;
		for(int i=0;i<n;i++)
		{
			b[i]=sc.nextInt();
			a[b[i]]++;
		}

		if(a[5]>0 || a[7]>0)
		{
			flag=1;
			System.out.println("-1");
		}
		else

		{

			while(a[1]>0 && a[2]>0 && a[4]>0)
			{
				stb.append("1 2 4\n");
				a[1]--;
				a[2]--;
				a[4]--;
			}

			while(a[1]>0 && a[2]>0 && a[6]>0)
			{
				stb.append("1 2 6\n");
				a[1]--;
				a[2]--;
				a[6]--;
			}
			while(a[1]>0&& a[3]>0 && a[6]>0)
			{
				stb.append("1 3 6\n");
				a[1]--;
				a[3]--;
				a[6]--;
			}
			for(int i=0;i<a.length;i++)
			{
				if(a[i]>0)
				{
					flag=1;
					System.out.println("-1");
					break;
				}
			}

			if(flag==0)
			{
				System.out.println(stb);
			}
		}
	}
}


// practice with rainboy
import java.io.*;
import java.util.*;

public class CF342A extends PrintWriter {
	CF342A() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF342A o = new CF342A(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int[] kk = new int[8];
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			kk[a]++;
		}
		if (kk[5] > 0 || kk[7] > 0) {
			println(-1);
			return;
		}
		if (kk[4] > kk[2] || kk[4] > kk[1]) {
			println(-1);
			return;
		}
		int k124 = kk[4];
		kk[1] -= k124;
		kk[2] -= k124;
		kk[4] -= k124;
		if (kk[1] != kk[6] || kk[1] != kk[2] + kk[3]) {
			println(-1);
			return;
		}
		int k126 = kk[2];
		int k136 = kk[3];
		while (k124-- > 0)
			println("1 2 4");
		while (k126-- > 0)
			println("1 2 6");
		while (k136-- > 0)
			println("1 3 6");
	}
}