#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
using ll = long long;
ll a[N], b[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
    map<ll, ll> f[2];
    f[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
      int cur = i % 2, lst = 1 - cur;
      f[cur].clear();
      ll A = a[i], B = 0;
      for (int j = 0; j < 3; ++j, ++A, B += b[i]) {
        for (auto k : f[lst])
          if (k.first != A) {
            ll tmp = B + k.second;
            if (f[cur].find(A) != f[cur].end()) {
              f[cur][A] = min(f[cur][A], tmp);
            } else {
              f[cur][A] = tmp;
            }
          }
      }
    }
    ll ans = LLONG_MAX;
    for (auto i : f[n % 2]) ans = min(ans, i.second);
    cout << ans << endl;
  }
}
