#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    long long a[n + 1];
    long long b[n + 1];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      cin >> b[i];
    }
    long long dp[n + 1][3];
    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 <= 2; j++) {
        dp[i][j] = 1000000000000000004;
        if (a[i] + j != a[i - 1]) {
          dp[i][j] = min(dp[i - 1][0] + j * b[i], dp[i][j]);
        }
        if (a[i] + j != a[i - 1] + 1) {
          dp[i][j] = min(dp[i - 1][1] + j * b[i], dp[i][j]);
        }
        if (a[i] + j != a[i - 1] + 2) {
          dp[i][j] = min(dp[i - 1][2] + j * b[i], dp[i][j]);
        }
      }
    }
    long long ans = min(dp[n - 1][0], dp[n - 1][1]);
    ans = min(ans, dp[n - 1][2]);
    cout << ans << endl;
  }
  return 0;
}
