#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;

#define lson (rt<<1)
#define rson (rt<<1|1)
#define mid ((l+r)>>1)

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

LL psum[4][MAXN];

struct Node {
    int l, r;
    LL sum[4], tag[4];
    void change(int i, int v) {
        tag[i] = (tag[i] + v) % MOD;
        sum[i] += psum[i][r] * v % MOD;
        if (l) sum[i] -= psum[i][l - 1] * v % MOD;
        sum[i] = (sum[i] + MOD) % MOD;
    }
} A[MAXN << 2];

void build(int rt, int l, int r) {
    A[rt].l = l; A[rt].r = r;
    for (int i = 0; i < 4; ++ i) A[rt].sum[i] = A[rt].tag[i] = 0;
    if (l == r) return;
    build(lson, l, mid); build(rson, mid + 1, r);
}

int a, b, c, d;

inline void pushdown(int rt) {
    for (int i = 0; i < 4; ++ i) {
        if (A[rt].tag[i]) {
            A[lson].change(i, A[rt].tag[i]);
            A[rson].change(i, A[rt].tag[i]);
            A[rt].tag[i] = 0;
        }
    }
}

inline void update(int rt) {
    for (int i = 0; i < 4; ++ i) {
        A[rt].sum[i] = A[lson].sum[i] + A[rson].sum[i];
        A[rt].sum[i] %= MOD;
    }
}

void modify(int rt, int l, int r, int L, int R) {
    if (L <= l && R >= r) {
        A[rt].change(3, a);
        A[rt].change(2, b);
        A[rt].change(1, c);
        A[rt].change(0, d);
        return;
    }
    pushdown(rt);
    if (L <= mid) modify(lson, l, mid, L, R);
    if (R > mid) modify(rson, mid + 1, r, L, R);
    update(rt);
}

LL ret[4];

void query(int rt, int l, int r, int L, int R) {
    if (L <= l && R >= r) {
        for (int i = 0; i < 4; ++ i) ret[i] += A[rt].sum[i];
        return;
    }
    pushdown(rt);
    if (L <= mid) query(lson, l, mid, L, R);
    if (R > mid) query(rson, mid + 1, r, L, R);
}

int main() {
    psum[0][0] = psum[1][0] = psum[2][0] = psum[3][0] = 0;
    psum[0][0] = 1;
    for (int i = 1; i < MAXN; ++ i) {
        psum[0][i] = 1 + psum[0][i - 1];
        psum[1][i] = (psum[1][i - 1] + i) % MOD;
        psum[2][i] = (psum[2][i - 1] + (LL)i * i % MOD) % MOD;
        psum[3][i] = (psum[3][i - 1] + (LL)i * i % MOD * i % MOD) % MOD;
    }
    int T; scanf("%d", &T);
    for (int cas = 1; cas <= T; ++ cas) {
        int N; scanf("%d", &N);
        build(1, 0, 1000000);
        printf("Case #%d:\n", cas);
        while (N --) {
            char st[10];
            int l, r;
            scanf("%s%d%d%d%d%d%d", st, &l, &r, &a, &b, &c, &d);
            if (st[0] == 'p') {
                modify(1, 0, 1000000, l, r);
            }
            else {
                for (int i = 0; i < 4; ++ i) ret[i] = 0;
                query(1, 0, 1000000, l, r);
                LL E = 0;
                for (int i = 0; i < 4; ++ i) E += ret[i];
                E %= MOD;
                printf("%lld\n", E);
                int x1 = E * l % 1000000;
                int x2 = E * r % 1000000;
                l = min(x1, x2);
                r = max(x1, x2);
                modify(1, 0, 1000000, l, r);
            }
        }
    }
}
