Under construction

Still being built. Things may change

Collection

Interview

Time limit5sMemory limit1024 MB

Summary
Given up to 10 test cases, add x coins to each type in a range, clear all coins in a range, and print the total value of the collection on each query.
Level

Medium6 of 10

Topics
Segment tree, Prefix sum
Solved
No attempts yet

Problem

You are collecting coins! You want to know how much your coins are worth.

From time to time, you pick up bags of coins and add them to your collection. Because you want to know exactly how many coins of each type you have, you keep all coins of a given type together. You may also lose all of your coins of several types.

At every moment, you want to be able to determine the total value of your coins quickly.

Input

The first line contains TT, the number of test cases. TT is at most 10.

The next line contains two positive integers NN and QQ, where 1≤N≤2×1061 \le N \le 2 \times 10^6 and 1≤Q≤1041 \le Q \le 10^4. The value of coin type VV is (V mod 10)+1(V \bmod 10) + 1.

Each of the next QQ lines has one of the following forms: "1 a b x", "2 a b", or "3".

For the form "1 a b x", you gain xx coins of every type from aa to bb inclusive.

For the form "2 a b", you lose all of your coins of every type from aa to bb inclusive.

For the form "3", compute the total value of all your coins.

You start with no coins. You may assume 1≤a≤b≤N1 \le a \le b \le N and 1≤x≤101 \le x \le 10.

Output

For every line of the form "3", print the total value of all your coins on a separate line.

Examples1

  1. Example 1

    Input
    1
    10 10
    1 2 5 10
    3
    2 3 5
    3
    1 5 8 10
    3
    1 7 9 2
    3
    2 5 9
    3
    
    Expected output
    140
    20
    280
    328
    20