#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9 + 7;
const ll inf = (LLONG_MAX >> 1);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<pair<ll, ll>> vp(n);
    for (int i = 0; i < n; ++i) cin >> vp[i].first >> vp[i].second;
    vector<vector<ll>> dp(3, vector<ll>(n, inf));
    dp[0][0] = 0;
    dp[1][0] = vp[0].second;
    dp[2][0] = 2 * vp[0].second;
    for (int i = 1; i < n; ++i) {
      for (int idx_i = 0; idx_i < 3; ++idx_i) {
        for (int idx_j = 0; idx_j < 3; ++idx_j) {
          if (vp[i].first + idx_i != vp[i - 1].first + idx_j) {
            dp[idx_i][i] =
                min(dp[idx_i][i], dp[idx_j][i - 1] + idx_i * vp[i].second);
          }
        }
      }
    }
    ll ans = min(dp[0][n - 1], dp[1][n - 1]);
    ans = min(ans, dp[2][n - 1]);
    cout << ans << "\n";
  }
  return 0;
}
