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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); ++i)

ll INF = 1ll << 60;

// UnionFind木
const int MAX = 200010;
int par[MAX], c[MAX];
map<int,int> m[MAX];

void init(){
  rep(i, 0, MAX){
    par[i] = -1;
    m[i][c[i]] = 1;
  }
}

int root(int x){
  if(par[x] < 0){
    return x;
  }
  return par[x] = root(par[x]);
}

int size(int x){
  return -par[root(x)];
}

void unite(int x, int y){
  int rx = root(x);
  int ry = root(y);
  if(rx == ry){
    return;
  }
  if(size(rx) < size(ry)){
    swap(rx, ry);
  }
  for(auto [key,value]:m[ry]){
    if(m[rx].count(key))
      m[rx][key] += value;
    else
      m[rx][key] = value;
  }
  par[rx] += par[ry];
  par[ry] = rx;
  return;
}

bool same(int x, int y){
  int rx = root(x);
  int ry = root(y);
  if(rx < 0 || ry < 0){
    if(rx >= 0){
      return rx == y;
    }
    if(ry >= 0){
      return ry == x;
    }
    return false;
  }
  return rx == ry;
}

int main(){
  int n, q;
  cin >> n >> q;
  rep(i, 0, n){
    cin >> c[i];
    c[i]--;
  }
  
  init();
  
  rep(i, 0, q){
    int t, a, b;
    cin >> t >> a >> b;
    t--;a--;b--;
    if(t){
      cout << m[root(a)][b] << endl;
    }
    else
      unite(a,b);
  }
  
  return 0;
  
}
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;

static const int  MAX_INT  = std::numeric_limits<int>::max();
static const long MAX_LONG = std::numeric_limits<long>::max();
static const ll   MAX_LL   = std::numeric_limits<long long>::max();

#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////

struct mint {
    static const int mod = 1000000007;
    long long x; // typedef long long ll;
    mint(long long x = 0) :x((x%mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x; }
std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x; }

void countNb(ll& res) {
    ll n, a, b; cin >> n >> a >> b;

    // ensure A <= B
    if (b < a) {
        ll tmp = a;
        a = b;
        b = tmp;
    }

    mint N(n), A(a), B(b);

    mint nbA = N - (A - 1); nbA = nbA * nbA;
    mint nbB = N - (B - 1); nbB = nbB * nbB;
    mint nbtotal = nbA * nbB;

    // dupulication: inside
    mint nbAb = B - (A - 1); nbAb = nbAb * nbAb;
    mint nbInside = nbAb * nbB;

    // cross
    mint cnt = 0;
    for (ll alpha = 1; alpha < a; ++alpha) {
        mint Alpha(alpha);
        mint nbCross = (B - A + Alpha * 2) * 4;
        mint nbIn = N - (B + Alpha - 1); nbIn = nbIn * nbIn;
        cnt += nbCross * nbIn;
    }

    mint count = nbtotal - nbInside - cnt;
    res = count.x;
}

void countNb2(ll& res) {
    mint N, A, B; cin >> N >> A >> B;
    ll nbSpace = N.x - A.x - B.x;
    mint x3 = (nbSpace >= 0) ? (N-A-B+2)*(N-A-B+1) : 0;
    mint x2 = (N-A+1)*(N-B+1) - x3;
    mint x1 = x2 * x2;
    mint total = (N-A+1)*(N-B+1) * (N-A+1)*(N-B+1);
    mint ans = total - x1;
    res = ans.x;
}


void Main() {
    ll T; cin >> T;
    vector<ll> res(T);
    for (ll i = 0; i < T; ++i) {
        countNb2(res[i]);
    }

    rep(i, T) {
        cout << res[i] << endl;
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(15);
    Main();

    double tmp;
    cin >> tmp;

    return 0;
}
