#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    int h[n], c[n];
    for (long long i = 0; i < n; i++) cin >> h[i] >> c[i];
    long long dp[n + 1][3];
    for (long long i = 0; i < 3; i++) dp[0][i] = 0;
    for (long long i = 1; i < n + 1; i++) {
      for (long long j = 0; j < 3; j++) {
        dp[i][j] = j * c[i - 1];
        if (i > 1) {
          long long minc = INTMAX_MAX;
          for (long long k = 0; k < 3; k++) {
            if (h[i - 2] + k != h[i - 1] + j) {
              minc = min(minc, dp[i - 1][k]);
            }
          }
          dp[i][j] += minc;
        }
      }
    }
    cout << min(min(dp[n][0], dp[n][1]), dp[n][2]) << endl;
  }
  return 0;
}
