#include <bits/stdc++.h>
using namespace std;
struct node {
  long long now, h1, h2;
};
node a[300007];
int num[300007], v[300007];
int main() {
  int T;
  int n;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
      scanf("%d %d", &num[i], &v[i]);
    }
    a[1].now = 0LL;
    a[1].h1 = v[1];
    a[1].h2 = v[1] * 2;
    for (int i = 2; i <= n; ++i) {
      if (num[i] == num[i - 1]) {
        a[i].now = min(a[i - 1].h1, a[i - 1].h2);
        a[i].h1 = min(a[i - 1].now, a[i - 1].h2) + v[i];
        a[i].h2 = min(a[i - 1].now, a[i - 1].h1) + v[i] * 2;
      }
      if (num[i] == num[i - 1] + 1) {
        a[i].now = min(a[i - 1].now, a[i - 1].h2);
        a[i].h1 = min(a[i - 1].now, a[i - 1].h1) + v[i];
        a[i].h2 = min(a[i - 1].h1, min(a[i - 1].now, a[i - 1].h2)) + v[i] * 2;
      }
      if (num[i] == num[i - 1] - 1) {
        a[i].now = min(a[i - 1].now, min(a[i - 1].h1, a[i - 1].h2));
        a[i].h1 = min(a[i - 1].h1, a[i - 1].h2) + v[i];
        a[i].h2 = min(a[i - 1].now, min(a[i - 1].h1, a[i - 1].h2)) + v[i] * 2;
      }
      if (abs(num[i] - num[i - 1]) > 1) {
        a[i].now = min(a[i - 1].now, min(a[i - 1].h1, a[i - 1].h2));
        a[i].h1 = a[i].now + v[i], a[i].h2 = a[i].now + v[i] * 2;
      }
    }
    printf("%lld\n", min(a[n].now, min(a[n].h1, a[n].h2)));
  }
  return 0;
}
