#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const double EPS = 1e-9;
const int INF = (int)1e9 + 7;
const long long LINF = (long long)1e18 + 7;
const double PI = acos(-1);
inline void IO() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
const int N = (int)3e5 + 10;
const int M = 10;
long long dp[M], dp2[M];
int a[N], b[N];
inline long long findMin(long long no, int i) {
  long long ans = LINF;
  for (int h = 0; h < M; h++) {
    if ((long long)a[i] + h == no) continue;
    ans = min(ans, dp[h]);
  }
  return ans;
}
inline void solve() {
  int q;
  cin >> q;
  for (int query = 0; query < q; query++) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    for (int h = 0; h < M; h++) {
      dp[h] = (long long)b[0] * h;
    }
    for (int i = 1; i < n; i++) {
      for (int h = 0; h < M; h++) {
        dp2[h] = (long long)b[i] * h + findMin((long long)a[i] + h, i - 1);
      }
      swap(dp, dp2);
    }
    cout << findMin(-1, 1) << "\n";
  }
}
int main() {
  IO();
  solve();
  return 0;
}
