#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
inline long long qp(long long n, int m, long long p) {
long long ans = 1, base = n;
while (m) {
if (m & 1) (ans *= base) %= p;
(base *= base) %= p;
m >>= 1;
}
return ans;
}
#define reg register
static char space[50000000],*sp=space;
template<typename T>
struct myalloc:allocator<T> {
myalloc() {
}
template<typename T2>
myalloc(const myalloc<T2> &a) {
}
template<typename T2>
myalloc<T>& operator=(const myalloc<T2> &a) {
return *this;
}
template<typename T2>
struct rebind {
typedef myalloc<T2> other;
}
;
inline T* allocate(size_t n) {
T *result=(T*)sp;
sp+=n*sizeof(T);
return result;
}
inline void deallocate(T* p,size_t n) {
}
}
;
char *p1,*p2,buf[10000005];
#define nc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,10000000,stdin),p1==p2)?EOF:*p1++)
int read() {
int x=0,f=1;
char ch=nc();
while(ch<48||ch>57) {
if(ch=='-')f=-1;
ch=nc();
}
while(ch>=48&&ch<=57) {
x=x*10+ch-48,ch=nc();
}
return x*f;
}
vector<int, myalloc<int>> Cubic[1000005], qwasd[1000005], rzh;
int t[1000005], a[1000005], b[1000005], c[1000005], qwq[1000005];
long long summ[1000005];
signed main() {
int n, m, x, y, v, op, bl=500;
n = read();
m = read();
for (int i=1; i<=n; i++) a[i] = read(), b[i] = read(), c[i] = read();
for (int i=1; i<=n; i++) qwq[i] = i;
sort(qwq+1, qwq+1+n, [](int x, int y) {
return a[x] < a[y];
}
);
for (int i=1; i<=n; i++) {
x = a[qwq[i]], y = b[qwq[i]], v = c[qwq[i]];
Cubic[y].push_back(x), qwasd[y].push_back(v), summ[y] += v, t[x] = 1;
if (Cubic[y].size() == bl) rzh.push_back(y);
}
for (int i=1; i<=m; i++) {
op = read(), x = read();
if (op == 1) {
for (int i: rzh) {
auto sc84bbs = lower_bound(Cubic[i].begin(), Cubic[i].end(), x);
int HWND=qwasd[i][sc84bbs-Cubic[i].begin()];
int kaffqlsb = (long long)HWND * HWND % (int)(1e9+7);
while (sc84bbs != Cubic[i].end() && *sc84bbs == x) summ[i] += kaffqlsb - HWND, qwasd[i][sc84bbs-Cubic[i].begin()] = kaffqlsb, sc84bbs++;
}
t[x] <<= 1;
while (t[x] >= (int)(1e9+6)) t[x] -= (int)(1e9+6);
continue;
}
if (Cubic[x].size() >= bl) cout << summ[x] % (int)(1e9+7); else {
long long qwq=0;
for (int i=0; i<Cubic[x].size(); i++) qwq += qp(qwasd[x][i], t[Cubic[x][i]], (int)(1e9+7));
cout << qwq % (int)(1e9+7);
}
cout << '\n';
}
}
/kel/kel