#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using VI = vector<int>;
using VLL = vector<long long>;
using VULL = vector<unsigned long long>;
using VS = vector<string>;
using VB = vector<bool>;
using VC = vector<char>;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using VPII = vector<pair<int, int>>;
using VPLL = vector<pair<long long, long long>>;
using VPULL = vector<pair<unsigned long long, unsigned long long>>;
using VVI = vector<vector<int>>;
using VVLL = vector<vector<long long>>;
using MII = map<int, int>;
using MLL = map<long long, long long>;
using SLL = set<long long>;
using SI = set<int>;
using PQI = priority_queue<int>;
template <class T>
T maxT(T a, T b) {
  return (a > b ? a : b);
}
template <class T>
T minT(T a, T b) {
  return (a < b ? a : b);
}
template <class T>
void setmax(T &a, T b) {
  a = (a > b ? a : b);
}
template <class T>
void setmin(T &a, T b) {
  a = (a < b ? a : b);
}
void fileio() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("debug.txt", "w", stderr);
}
void ofileio() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void clock_out() {
  cerr << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
template <typename... Args>
void readln(Args &...args) {
  ((cin >> args), ...);
}
template <typename... Args>
void writeln(Args... args) {
  ((cout << args << " "), ...);
}
const LL MOD = 1000000007;
const LL SIZE = 100000;
const int INF = 0x3f3f3f3f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LD PI = acos(-1);
const LL MAXN = (LL)1e9 + 1;
void solve() {
  int n;
  cin >> n;
  VLL a(n), b(n);
  for (LL i = 0; i < (LL)n; i++) cin >> a[i] >> b[i];
  LL dp[3][n];
  for (LL i = 0; i < (LL)n; i++) {
    dp[0][i] = LLONG_MAX;
    dp[1][i] = LLONG_MAX;
    dp[2][i] = LLONG_MAX;
  }
  dp[0][0] = 0;
  dp[1][0] = b[0];
  dp[2][0] = 2 * b[0];
  for (int i = 1; i < n; i++) {
    if (a[i] == a[i - 1]) {
      dp[0][i] = min(dp[1][i - 1], dp[2][i - 1]);
      dp[1][i] = min(dp[0][i - 1] + b[i], dp[2][i - 1] + b[i]);
      dp[2][i] = min(dp[1][i - 1] + 2 * b[i], dp[0][i - 1] + 2 * b[i]);
    } else {
      dp[0][i] = min(dp[0][i], dp[0][i - 1]);
      dp[1][i] = min(dp[1][i], dp[1][i - 1] + b[i]);
      dp[2][i] = min(dp[2][i], dp[2][i - 1] + 2 * b[i]);
      if (a[i] != a[i - 1] + 1) {
        dp[0][i] = min(dp[0][i], dp[1][i - 1]);
      }
      if (a[i] != a[i - 1] + 2) {
        dp[0][i] = min(dp[0][i], dp[2][i - 1]);
      }
      if (a[i] + 1 != a[i - 1]) {
        dp[1][i] = min(dp[1][i], dp[0][i - 1] + b[i]);
      }
      if (a[i] + 1 != a[i - 1] + 2) {
        dp[1][i] = min(dp[1][i], dp[2][i - 1] + b[i]);
      }
      if (a[i] + 2 != a[i - 1]) {
        dp[2][i] = min(dp[2][i], dp[0][i - 1] + 2 * b[i]);
      }
      if (a[i] + 2 != a[i - 1] + 1) {
        dp[2][i] = min(dp[2][i], dp[1][i - 1] + 2 * b[i]);
      }
    }
  }
  cout << min(dp[0][n - 1], min(dp[1][n - 1], dp[2][n - 1])) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  srand(time(NULL));
  1;
  LL t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  1;
  return 0;
}
