#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n], b[n];
    for (long long i = 0; i < n; i++) cin >> a[i] >> b[i];
    long long dp[n][3];
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j <= 2; j++) {
        dp[i][j] = 2e18;
      }
    }
    dp[0][0] = 0;
    dp[0][1] = b[0];
    dp[0][2] = 2 * b[0];
    for (long long i = 1; i < n; i++) {
      for (long long j = 0; j <= 2; j++) {
        for (long long x = 0; x <= 2; x++) {
          if (a[i - 1] + x != a[i] + j)
            dp[i][j] = min(j * b[i] + dp[i - 1][x], dp[i][j]);
        }
      }
    }
    cout << min(dp[n - 1][0], min(dp[n - 1][1], dp[n - 1][2])) << '\n';
  }
}
