#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  long long int A[n], B[n], dp[4][n];
  for (long long int i = 0; i < n; i++) {
    cin >> A[i];
    cin >> B[i];
    for (int j = 0; j < 4; j++) {
      dp[j][i] = 1e18;
    }
    dp[3][i] = A[i];
  }
  dp[0][0] = 0;
  dp[1][0] = B[0];
  dp[2][0] = 2 * B[0];
  for (long long int i = 1; i < n; i++) {
    for (long long int j = 0; j < 3; j++) {
      for (long long int k = 0; k < 3; k++) {
        if (A[i] + k != dp[3][i - 1] + j) {
          dp[k][i] = min(dp[k][i], dp[j][i - 1] + k * B[i]);
        }
      }
    }
  }
  long long int ans = 1e18;
  for (long long int i = 0; i < 3; i++) {
    ans = min(ans, dp[i][n - 1]);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
