#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> dp(10, INT64_MIN / 16), tp(10, 0);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    long long m11 = INT64_MIN / 16, m12 = INT64_MIN / 16, m13 = INT64_MIN / 16,
              m20 = INT64_MIN / 16, m30 = INT64_MIN / 16;
    for (int j = 0; j < k; j++) {
      long long cost, damage;
      cin >> cost >> damage;
      if (cost == 1 && damage > m11) {
        m13 = m12;
        m12 = m11;
        m11 = damage;
      } else if (cost == 1 && damage > m12) {
        m13 = m12;
        m12 = damage;
      } else if (cost == 1 && damage > m13) {
        m13 = damage;
      } else if (cost == 2 && damage > m20) {
        m20 = damage;
      } else if (cost == 3 && damage > m30) {
        m30 = damage;
      }
    }
    long long d1 = max(m11, max(m20, m30));
    long long d2 = max(m11 + m12, m11 + m20);
    long long d3 = m11 + m12 + m13;
    for (int j = 1; j < 10; j++) {
      tp[j] = dp[j];
      if (d1 > 0) tp[j] = max(tp[j], d1 + dp[(j - 1 + 10) % 10]);
      if (d2 > 0) tp[j] = max(tp[j], d2 + dp[(j - 2 + 10) % 10]);
      if (d3 > 0) tp[j] = max(tp[j], d3 + dp[(j - 3 + 10) % 10]);
    }
    tp[0] = dp[0];
    if (d1 > 0) tp[0] = max(tp[0], d1 + dp[9] + d1);
    if (d2 > 0)
      tp[0] = max(tp[0], d2 + dp[8] + (m12 > m20 ? m11 : max(m11, m20)));
    if (d3 > 0) tp[0] = max(tp[0], d3 + dp[7] + m11);
    dp = tp;
    for (int iter = 0; iter < 10; iter++) cout << dp[iter] << " ";
    cout << ";" << endl;
  }
  long long result = 0;
  for (int i = 0; i < 10; i++) {
    result = max(result, dp[i]);
  }
  cout << result << endl;
}
