#include <bits/stdc++.h>
using namespace std;
long long dp[300007][10], arr[300007], cost[300007];
int n;
long long dfs(int indx, long long add) {
  if (indx > n) return (long long)0;
  if (dp[indx][add] != -1) return dp[indx][add];
  long long res = 1000000000000000047;
  if (arr[indx - 1] + add != arr[indx] + (long long)(0))
    res = min(res, (long long)0 * cost[indx] + dfs(indx + 1, (long long)0));
  if (arr[indx - 1] + add != arr[indx] + (long long)(1))
    res = min(res, (long long)1 * cost[indx] + dfs(indx + 1, (long long)1));
  if (arr[indx - 1] + add != arr[indx] + (long long)(2))
    res = min(res, (long long)2 * cost[indx] + dfs(indx + 1, (long long)2));
  if (arr[indx - 1] + add != arr[indx] + (long long)(3))
    res = min(res, (long long)3 * cost[indx] + dfs(indx + 1, (long long)3));
  if (arr[indx - 1] + add != arr[indx] + (long long)(4))
    res = min(res, (long long)4 * cost[indx] + dfs(indx + 1, (long long)4));
  if (arr[indx - 1] + add != arr[indx] + (long long)(5))
    res = min(res, (long long)5 * cost[indx] + dfs(indx + 1, (long long)5));
  return dp[indx][add] = res;
}
void init(int n) {
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= 6; ++j) dp[i][j] = -1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int test;
  cin >> test;
  while (test--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> arr[i] >> cost[i];
    init(n);
    cout << dfs(1, 0) << endl;
  }
  return 0;
}
