#include <bits/stdc++.h>
using namespace std;
long long T, n, a[300100], b[300100], dp[300300][4];
long long solve(int i, int inc) {
  if (i == n) return 0;
  long long ret = 1e18 + 5;
  if (dp[i][inc] + 1) return dp[i][inc];
  if (i == 0 || a[i - 1] + inc != a[i]) ret = min(ret, solve(i + 1, 0));
  if (i == 0 || a[i - 1] + inc != a[i] + 1)
    ret = min(ret, solve(i + 1, 1) + b[i]);
  if (i == 0 || a[i - 1] + inc != a[i] + 2)
    ret = min(ret, solve(i + 1, 2) + 2 * b[i]);
  return dp[i][inc] = ret;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 0; i < n; i++) dp[i][0] = dp[i][1] = dp[i][2] = -1;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    cout << solve(0, 0) << endl;
  }
  return 0;
}
