#include <bits/stdc++.h>
using namespace std;
int q;
const int N = 3e5 + 10;
long long dp[N][3], a[N], b[N];
int main() {
  scanf("%d", &q);
  while (q--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%lld%lld", &a[i], &b[i]);
    dp[1][0] = 0, dp[1][1] = b[1], dp[1][2] = 2 * b[1];
    for (int i = 2; i <= n; i++) {
      if (a[i] == a[i - 1])
        dp[i][0] = min(dp[i - 1][1], dp[i - 1][2]);
      else if (a[i] == a[i - 1] + 1)
        dp[i][0] = min(dp[i - 1][0], dp[i - 1][2]);
      else if (a[i] == a[i - 1] + 2)
        dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]);
      else
        dp[i][0] = min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]);
      if (a[i] == a[i - 1] + 1)
        dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]);
      else if (a[i] == a[i - 1])
        dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]);
      else if (a[i] == a[i - 1] - 1)
        dp[i][1] = min(dp[i - 1][1], dp[i - 1][2]);
      else
        dp[i][1] = min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]);
      dp[i][1] += b[i];
      if (a[i] == a[i - 1])
        dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]);
      else if (a[i] == a[i - 1] - 1)
        dp[i][2] = min(dp[i - 1][0], dp[i - 1][2]);
      else if (a[i] == a[i - 1] - 2)
        dp[i][2] = min(dp[i - 1][1], dp[i - 1][2]);
      else
        dp[i][2] = min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]);
      dp[i][2] += 2 * b[i];
    }
    printf("%lld\n", min(min(dp[n][0], dp[n][1]), dp[n][2]));
  }
  return 0;
}
