#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x7fffffffffffffff;
int T, n;
long long a[300005];
long long b[300005];
long long dp[300005][3];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    dp[0][0] = 0;
    dp[0][1] = b[0];
    dp[0][2] = b[0] * 2;
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        dp[i][j] = INF;
        for (int k = 0; k < 3; k++) {
          if (a[i - 1] + k != a[i] + j) {
            dp[i][j] = min(dp[i][j], dp[i - 1][k] + b[i] * j);
          }
        }
      }
    }
    long long ans = INF;
    for (int i = 0; i < 3; i++) {
      ans = min(ans, dp[n - 1][i]);
    }
    cout << ans << endl;
  }
  return 0;
}
