#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MOD = 1e9 + 7;

struct node
{
	LL L, R;
	LL add[4];
	LL sum;
}ST[1000010 << 2];

LL inv2, inv4, inv6;

void build(int k, LL L, LL R)
{
	ST[k].L = L, ST[k].R = R;
	ST[k].sum = 0;
	for (int i = 0; i < 4; i++) {
		ST[k].add[i] = 0;
	}
	if (L == R) return;
	LL mid = (L + R) >> 1;
	build(k << 1, L, mid);
	build(k << 1 | 1, mid + 1, R);
}

inline LL POW(LL a, LL b)
{
	LL res = 1;
	while (b) {
		if (b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

LL sum[4][1000010];

inline LL fun(int tag, LL L, LL R)
{
	if (L != 0) return (sum[tag][R] - sum[tag][L - 1] + MOD) % MOD;
	return sum[tag][R];
}

inline void down(int k)
{
	if (ST[k].L == ST[k].R) return;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 2; j++) {
			LL delta = fun(3 - i, ST[k << 1 | j].L, ST[k << 1 | j].R);
			ST[k << 1 | j].add[i] += ST[k].add[i];
			ST[k << 1 | j].add[i] %= MOD;
			ST[k << 1 | j].sum += delta * ST[k].add[i] % MOD;
			ST[k << 1 | j].sum %= MOD;
		}
		ST[k].add[i] = 0;
	}
}

/*
inline void up(int k)
{
	if (ST[k].L == ST[k].R) return;
	ST[k].sum = (ST[k << 1].sum + ST[k << 1 | 1].sum) % MOD;
}
*/

void gao(int k, int L, int R, LL add[4])
{
	if (L > R) return;
	for (int i = 0; i < 4; i++) {
		LL delta = fun(3 - i, L, R);
		ST[k].sum += delta * add[i] % MOD;
		ST[k].sum %= MOD;
	}
	if (L == ST[k].L && ST[k].R == R) {
		for (int i = 0; i < 4; i++) {
			ST[k].add[i] += add[i];
			ST[k].add[i] %= MOD;
		}
		return;
	}
	down(k);
	LL mid = (ST[k].L + ST[k].R) >> 1;
	if (R <= mid) {
		gao(k << 1, L, R, add);
	}
	else 
	if (L > mid){
		gao(k << 1 | 1, L, R, add);
	}
	else {
		gao(k << 1, L, mid, add);
		gao(k << 1 | 1, mid + 1, R, add);
	}
}

LL get(int k, LL L, LL R)
{
	if (L > R) return 0;
	if (L == ST[k].L && ST[k].R == R) return ST[k].sum;
	down(k);
	LL mid = (ST[k].L + ST[k].R) >> 1;
	LL res = 0;
	if (R <= mid) {
		res = get(k << 1, L, R);
	}
	else 
	if (L > mid) {
		res = get(k << 1 | 1, L, R);
	}
	else {
		res = (get(k << 1, L, mid) + get(k << 1 | 1, mid + 1, R)) % MOD;
	}
	return res;
}

int main()
{
	inv2 = POW(2, MOD - 2);
	inv4 = POW(4, MOD - 2);
	inv6 = POW(6, MOD - 2);
	for (long long i = 1; i <= 1000000; i++) {
		sum[0][i] = (sum[0][i - 1] + 1) % MOD;
		sum[1][i] = (sum[1][i - 1] + i) % MOD;
		sum[2][i] = (sum[2][i - 1] + i * i) % MOD;
		sum[3][i] = (sum[3][i - 1] + i * i % MOD * i % MOD) % MOD;
	}

	int T, n;
	scanf("%d", &T);
	for (int cas = 1; cas <= T; cas++) {
		scanf("%d", &n);
		build(1, 0, 1000000);
		printf("Case #%d:\n", cas);
		for (int i = 0; i < n; i++) { 
			static char opt[10];
			LL x1, x2, add[4];
			scanf("%s%lld%lld", opt, &x1, &x2);
			for (int i = 0; i < 4; i++) {
				scanf("%lld", add + i);
				add[i] = (add[i] % MOD + MOD) % MOD;
			}
			if (*opt == 'p') {
				gao(1, x1, x2, add);
			}
			if (*opt == 't') {
				LL sum = get(1, x1, x2);
				printf("%lld\n", sum);
				LL r1 = x1 * sum % 1000000;
				LL r2 = x2 * sum % 1000000;
				if (r1 > r2) swap(r1, r2);
				gao(1, r1, r2, add);
			}
		}
	}
	return 0;
}

