#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const long long int inf = 1e18;
long long int a[N];
long long int b[N];
long long int dp[N][3];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%lld %lld", &a[i], &b[i]);
    dp[1][0] = 0;
    dp[1][1] = b[1];
    dp[1][2] = 2 * b[1];
    for (int i = 2; i <= n; i++) {
      dp[i][0] = dp[i][1] = dp[i][2] = inf;
      for (int j = 0; j <= 2; j++) {
        for (int k = 0; k <= 2; k++) {
          if (a[i - 1] + j == a[i] + k) continue;
          dp[i][k] = min(dp[i][k], dp[i - 1][j] + k * b[i]);
        }
      }
    }
    printf("%lld\n", min(dp[n][0], min(dp[n][1], dp[n][2])));
  }
  return 0;
}
