#include <bits/stdc++.h>
using namespace std;
const double PI = atan(1.0) * 4;
const long long int INF = 100000000000000003;
const int32_t LOG = 21;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int q;
  cin >> q;
  for (long long int ii = 0; ii < q; ii++) {
    long long int n;
    cin >> n;
    long long int a[n], b[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    long long int dp[n][3];
    dp[0][0] = 0;
    dp[0][1] = b[0];
    dp[0][2] = 2 * b[0];
    for (long long int i = 1; i < n; i++) {
      dp[i][0] = dp[i][1] = dp[i][2] = INF;
      for (long long int j = 0; j < 3; j++) {
        for (long long int k = 0; k < 3; k++) {
          if (a[i] + j != a[i - 1] + k) {
            dp[i][j] = min(dp[i][j], dp[i - 1][k] + j * b[i]);
          }
        }
      }
    }
    cout << min({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << '\n';
  }
  return 0;
}
