codeforces#P1176F. Destroy it!

Destroy it!

Description

You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.

The boss battle consists of nn turns. During each turn, you will get several cards. Each card has two parameters: its cost cic_i and damage did_i. You may play some of your cards during each turn in some sequence (you choose the cards and the exact order they are played), as long as the total cost of the cards you play during the turn does not exceed 33. After playing some (possibly zero) cards, you end your turn, and all cards you didn't play are discarded. Note that you can use each card at most once.

Your character has also found an artifact that boosts the damage of some of your actions: every 1010-th card you play deals double damage.

What is the maximum possible damage you can deal during nn turns?

The first line contains one integer nn (1n21051 \le n \le 2 \cdot 10^5) — the number of turns.

Then nn blocks of input follow, the ii-th block representing the cards you get during the ii-th turn.

Each block begins with a line containing one integer kik_i (1ki21051 \le k_i \le 2 \cdot 10^5) — the number of cards you get during ii-th turn. Then kik_i lines follow, each containing two integers cjc_j and djd_j (1cj31 \le c_j \le 3, 1dj1091 \le d_j \le 10^9) — the parameters of the corresponding card.

It is guaranteed that i=1nki2105\sum \limits_{i = 1}^{n} k_i \le 2 \cdot 10^5.

Print one integer — the maximum damage you may deal.

Input

The first line contains one integer nn (1n21051 \le n \le 2 \cdot 10^5) — the number of turns.

Then nn blocks of input follow, the ii-th block representing the cards you get during the ii-th turn.

Each block begins with a line containing one integer kik_i (1ki21051 \le k_i \le 2 \cdot 10^5) — the number of cards you get during ii-th turn. Then kik_i lines follow, each containing two integers cjc_j and djd_j (1cj31 \le c_j \le 3, 1dj1091 \le d_j \le 10^9) — the parameters of the corresponding card.

It is guaranteed that i=1nki2105\sum \limits_{i = 1}^{n} k_i \le 2 \cdot 10^5.

Output

Print one integer — the maximum damage you may deal.

Samples

输入数据 1

5
3
1 6
1 7
1 5
2
1 4
1 3
3
1 10
3 5
2 3
3
1 15
2 4
1 10
1
1 100

输出数据 1

263

Note

In the example test the best course of action is as follows:

During the first turn, play all three cards in any order and deal 1818 damage.

During the second turn, play both cards and deal 77 damage.

During the third turn, play the first and the third card and deal 1313 damage.

During the fourth turn, play the first and the third card and deal 2525 damage.

During the fifth turn, play the only card, which will deal double damage (200200).