#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<int> > VVI;
typedef priority_queue<int, vector<int>, greater<int> > PQ;
const int MAX = 3e5 + 10, MOD = 1e9 + 7;
long long int H[MAX], C[MAX], n, dp[MAX][3];
long long int solve(int idx, int prev) {
  if (idx > n) return 0;
  if (dp[idx][prev] != -1) return dp[idx][prev];
  long long int res = 1e18 + 100;
  for (long long int i = 0, cost = 0; i <= 2; i++, cost += C[idx]) {
    if (prev + H[idx - 1] != i + H[idx])
      res = min(res, cost + solve(idx + 1, i));
  }
  return dp[idx][prev] = res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= 10; j++) dp[i][j] = -1;
    H[0] = 1e18;
    for (int i = 1; i <= n; i++) {
      cin >> H[i] >> C[i];
    }
    H[n + 1] = 1e18;
    long long int res = solve(1, 0);
    cout << res << "\n";
  }
  return 0;
}
