#include <bits/stdc++.h>
using namespace std;
const int MINF = INT_MIN;
const int sizer = 3e5 + 5;
int n;
long long A[sizer], B[sizer], dp[sizer][3];
long long findCost(int index, int add) {
  if (index >= n) return 0;
  if (dp[index][add] != -1) return dp[index][add];
  long long ans = LLONG_MAX;
  for (int i = 0; i < 3; ++i) {
    if (index == 0 || add + A[index - 1] != i + A[index])
      ans = min(ans, findCost(index + 1, i) + i * 1ll * B[index]);
  }
  return dp[index][add] = ans;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    cin >> n;
    for (int i = 0; i < n; ++i) {
      scanf("%d", A + i);
      scanf("%d", B + i);
    }
    for (int i = 0; i <= n; ++i) dp[i][0] = dp[i][1] = dp[i][2] = -1;
    printf("%lld\n", findCost(0, 0));
  }
  return 0;
}
