#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll md = 1000000007;
ll exp(ll a, ll b) {
  ll r = 1ll;
  while (b > 0) {
    if (b & 1) {
      r = r * (a % md);
      r = (r + md) % md;
    }
    b >>= 1;
    a = (a % md) * (a % md);
    a = (a + md) % md;
  }
  return (r + md) % md;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll Min(ll a, ll b) {
  if (a < b) return a;
  return b;
}
ll Max(ll a, ll b) {
  if (a > b) return a;
  return b;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    long long a[n], b[n], dp[n][5];
    for (ll i = 0; i <= n - 1; ++i) cin >> a[i] >> b[i];
    for (ll i = 0; i <= n - 1; ++i)
      for (ll j = 0; j <= 4; ++j) dp[i][j] = 1e18;
    for (ll i = 0; i <= 4; ++i) dp[0][i] = i * b[0];
    for (ll i = 1; i <= n - 1; ++i) {
      for (ll j = 0; j <= 4; ++j)
        for (ll k = 0; k <= 4; ++k) {
          if (a[i] + j != a[i - 1] + k)
            dp[i][j] = Min(dp[i][j], dp[i - 1][k] + b[i] * j);
        }
    }
    long long ans = 1e18;
    for (ll i = 0; i <= 4; ++i) ans = Min(ans, dp[n - 1][i]);
    cout << ans;
    cout << '\n';
  }
  return 0;
}
