text: /*=============================================================================
  #  Author:          Teerapat Jenrungrot - https://github.com/mjenrungrot/
  #  FileName:        10201.cc
  #  Description:     UVa Online Judge - 10201
  =============================================================================*/
  #include <bits/stdc++.h>
  #pragma GCC optimizer("Ofast")
  #pragma GCC target("avx2")
  using namespace std;
  
  typedef pair<int, int> ii;
  typedef pair<long long, long long> ll;
  typedef pair<double, double> dd;
  typedef tuple<int, int, int> iii;
  typedef tuple<long long, long long, long long> lll;
  typedef tuple<double, double, double> ddd;
  typedef vector<string> vs;
  typedef vector<int> vi;
  typedef vector<vector<int>> vvi;
  typedef vector<long long> vl;
  typedef vector<vector<long long>> vvl;
  typedef vector<double> vd;
  typedef vector<vector<double>> vvd;
  typedef vector<ii> vii;
  typedef vector<ll> vll;
  typedef vector<dd> vdd;
  
  // Debug Snippets
  
  void __print(int x) { cerr << x; }
  void __print(long x) { cerr << x; }
  void __print(long long x) { cerr << x; }
  void __print(unsigned x) { cerr << x; }
  void __print(unsigned long x) { cerr << x; }
  void __print(unsigned long long x) { cerr << x; }
  void __print(float x) { cerr << x; }
  void __print(double x) { cerr << x; }
  void __print(long double x) { cerr << x; }
  void __print(char x) { cerr << '\'' << x << '\''; }
  void __print(const char* x) { cerr << '\"' << x << '\"'; }
  void __print(const string& x) { cerr << '\"' << x << '\"'; }
  void __print(bool x) { cerr << (x ? "true" : "false"); }
  
  template <typename T, typename V>
  void __print(const pair<T, V>& x) {
      cerr << '{';
      __print(x.first);
      cerr << ',';
      __print(x.second);
      cerr << '}';
  }
  template <typename T>
  void __print(const T& x) {
      int f = 0;
      cerr << '{';
      for (auto& i : x) cerr << (f++ ? "," : ""), __print(i);
      cerr << "}";
  }
  void _print() { cerr << "]\n"; }
  template <typename T, typename... V>
  void _print(T t, V... v) {
      __print(t);
      if (sizeof...(v)) cerr << ", ";
      _print(v...);
  }
  
  #define debug(x...)               \
      cerr << "[" << #x << "] = ["; \
      _print(x)
  
  template <class Ch, class Tr, class Container>
  basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os,
                                    Container const& x) {
      os << "{ ";
      for (auto& y : x) os << y << " ";
      return os << "}";
  }
  
  template <class X, class Y>
  ostream& operator<<(ostream& os, pair<X, Y> const& p) {
      return os << "[ " << p.first << ", " << p.second << "]";
  }
  
  // End Debug Snippets
  
  vs split(string line) {
      vs output;
      istringstream iss(line);
      string tmp;
      while (iss >> tmp) {
          output.push_back(tmp);
      }
      return output;
  }
  
  vs split(string line, regex re) {
      vs output;
      sregex_token_iterator it(line.begin(), line.end(), re, -1), it_end;
      while (it != it_end) {
          output.push_back(it->str());
          it++;
      }
      return output;
  }
  
  const int INF_INT = 1e9 + 7;
  const long long INF_LL = 1e18;
  const int MAX_DIST = 10005;
  const int MAX_CAP = 200;
  
  int dist, dp[MAX_DIST][MAX_CAP + 1];
  int is_station[MAX_DIST];
  int min_price[MAX_DIST];
  
  void solve() {
      memset(is_station, 0, sizeof(is_station));
      for (int i = 0; i < MAX_DIST; i++) min_price[i] = INF_INT;
  
      string line;
  
      cin >> dist;
      getline(cin, line);
  
      while (getline(cin, line)) {
          if (line == "") break;
  
          istringstream iss(line);
  
          int x, y;
          iss >> x >> y;
  
          is_station[x] = true;
          min_price[x] = min(min_price[x], y);
  
          if (cin.eof()) break;
      }
  
      for (int i = 0; i < MAX_DIST; i++)
          for (int j = 0; j <= MAX_CAP; j++) dp[i][j] = INF_INT;
      dp[0][MAX_CAP / 2] = 0;
  
      for (int i = 1; i <= dist; i++) {
          for (int c = 0; c <= MAX_CAP; c++) {
              if (c + 1 <= MAX_CAP) {
                  dp[i][c] = min(dp[i][c], dp[i - 1][c + 1]);
              }
          }
  
          for (int c = 1; c <= MAX_CAP; c++) {
              if (is_station[i]) {
                  dp[i][c] = min(dp[i][c], dp[i][c - 1] + min_price[i]);
              }
          }
      }
  
      int ans = INF_INT;
      for (int c = MAX_CAP / 2; c <= MAX_CAP; c++) ans = min(ans, dp[dist][c]);
  
      if (ans == INF_INT)
          cout << "Impossible" << endl;
      else
          cout << ans << endl;
  }
  
  int main() {
      ios::sync_with_stdio(false);
      cin.tie(0);
  
      string line;
      int T;
      cin >> T;
      getline(cin, line);  // \n
      getline(cin, line);  // empty line
  
      while (T--) {
          solve();
          if (T) cout << endl;
      }
  
      return 0;
  }