#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  int q;
  cin >> q;
  for (int gh = (int)(0); gh <= (int)(q - 1); gh++) {
    int n;
    cin >> n;
    vector<long long> cost(n);
    vector<long long> arr(n);
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      cin >> cost[i];
    }
    vector<vector<long long>> dp(n, vector<long long>(3, 1e18));
    for (int i = 0; i < 3; i++) dp[0][i] = (long long)i * cost[0];
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          if (arr[i] + j != arr[i - 1] + k)
            dp[i][j] = min(dp[i][j], dp[i - 1][k] + (long long)j * cost[i]);
        }
      }
    }
    long long ans = 1e18 + 10;
    for (int i = 0; i < 3; i++) ans = min(ans, dp[n - 1][i]);
    cout << ans << '\n';
  }
  return 0;
}
