#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k, c[N], d[N];
long long f[N][12], ans, g[12][5][5];
int main() {
  memset(f, 0xc0, sizeof f);
  f[0][0] = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d%d", &c[j], &d[j]);
    }
    memset(g, 0xc0, sizeof g);
    for (int j = 0; j < 10; j++) {
      g[j][0][0] = f[i - 1][j];
    }
    for (int j = 1; j <= k; j++) {
      for (int o = 3; o; o--) {
        for (int p = 3; p; p--) {
          for (int l = 0; l < 10; l++) {
            if (p < c[j]) {
              continue;
            }
            if (l) {
              g[l][o][p] = max(g[l][o][p], g[l - 1][o - 1][p - c[j]] + d[j]);
            } else {
              g[l][o][p] = max(g[l][o][p], g[9][o - 1][p - c[j]] + (d[j] << 1));
            }
          }
        }
      }
    }
    for (int j = 0; j < 10; j++) {
      for (int o = 0; o <= 3; o++) {
        for (int p = 0; p <= 3; p++) {
          f[i][j] = max(f[i][j], g[j][o][p]);
        }
      }
    }
  }
  for (int i = 0; i < 10; i++) {
    ans = max(ans, f[n][i]);
  }
  printf("%lld\n", ans);
  return 0;
}
