#include <bits/stdc++.h>
using namespace std;
template <typename T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
const long long MOD = 1e9 + 7;
int Q, N;
long long a[300100], b[300100];
long long dp[3][300100];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> Q;
  while (Q-- > 0) {
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> a[i] >> b[i];
    for (int i = 1; i <= N; i++) {
      dp[0][i] = dp[1][i] = dp[2][i] = 1e18;
      for (int j = 0; j <= 2; j++) {
        for (int k = 0; k <= 2; k++) {
          if (i == 1 || a[i - 1] + j != a[i] + k)
            dp[k][i] = min(dp[k][i], dp[j][i - 1] + b[i] * k);
        }
      }
    }
    cout << min(dp[0][N], min(dp[1][N], dp[2][N])) << '\n';
  }
  return 0;
}
