#include <bits/stdc++.h>
using namespace std;
long long arr[300010], val[300010], dp[300010][3];
int main() {
  int tc;
  cin >> tc;
  for (int cs = 1; cs <= tc; cs++) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      long long x, y;
      scanf("%lld%lld", &x, &y);
      arr[i] = x;
      val[i] = y;
    }
    dp[n - 1][0] = 0;
    dp[n - 1][1] = val[n - 1];
    dp[n - 1][2] = 2 * val[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      long long vv = arr[i];
      for (int j = 0; j < 3; j++) {
        long long ans = 2e18;
        long long vvv = arr[i + 1];
        if (vv != vvv) ans = min(ans, dp[i + 1][0]);
        vvv++;
        if (vv != vvv) ans = min(ans, dp[i + 1][1]);
        vvv++;
        if (vv != vvv) ans = min(ans, dp[i + 1][2]);
        dp[i][j] = (val[i] * j) + ans;
        vv++;
      }
    }
    long long ans = min({dp[0][0], dp[0][1], dp[0][2]});
    printf("%lld\n", ans);
  }
  return 0;
}
