#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<long long>;
template <class T>
istream &operator>>(istream &, vector<T> &);
template <class T>
ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U>
istream &operator>>(istream &, pair<T, U> &);
template <class T, class U>
ostream &operator<<(ostream &, const pair<T, U> &);
constexpr int INF = 0x3f3f3f3f;
constexpr ll BINF = 0x3f3f3f3f3f3f3f3fLL;
int solve() {
  int n;
  cin >> n;
  const int M = 100;
  vector<ll> dp(M, -BINF), dp2(M, -BINF);
  dp2[0] = 0;
  for (int i = 0; i < n; i++) {
    vvi cs(3);
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int c, d;
      cin >> c >> d;
      cs[c - 1].push_back(d);
    }
    for (int j = 0; j < 3; j++)
      sort(cs[j].begin(), cs[j].end()), reverse(cs[j].begin(), cs[j].end());
    for (int j = 0; j < M; j++) dp[j] = -BINF;
    for (int x = 0; x <= 3 && x <= cs[0].size(); x++)
      for (int y = 0; y <= 3 && y <= cs[1].size(); y++)
        for (int z = 0; z <= 3 && z <= cs[2].size(); z++) {
          int cost = x + 2 * y + 3 * z;
          if (cost > 3) continue;
          int cards = x + y + z;
          vector<ll> dams;
          for (int j = 0; j < x; j++) dams.push_back(cs[0][j]);
          for (int j = 0; j < y; j++) dams.push_back(cs[1][j]);
          for (int j = 0; j < z; j++) dams.push_back(cs[2][j]);
          sort(dams.begin(), dams.end());
          ll dam = accumulate(dams.begin(), dams.end(), 0);
          for (int j = 0; j < M; j++) {
            if ((j + cards) / 10 != j / 10) {
              dp[(j + cards) % M] =
                  max(dp[(j + cards) % M], dp2[j] + dam + dams.back());
            } else {
              dp[(j + cards) % M] = max(dp[(j + cards) % M], dp2[j] + dam);
            }
          }
        }
    dp2 = dp;
  }
  cout << *max_element(dp.begin(), dp.end()) << endl;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  solve();
  return 0;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto it = v.begin(); it != v.end(); ++it) is >> *it;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto it = v.begin(); it != v.end();)
    os << *it, os << " \n"[++it == v.end()];
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  return is >> p.first >> p.second;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << p.first << ' ' << p.second;
}
