#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
void solve() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<pair<long long int, long long int>> arr_even_index;
    vector<pair<long long int, long long int>> arr_odd_index;
    for (long long int i = 0; i < n; ++i) {
      long long int a;
      cin >> a;
      if (a % 2 == i % 2)
        continue;
      else if (a % 2 == 0 && i % 2 != 0)
        arr_odd_index.emplace_back((make_pair(a, i)));
      else if (a % 2 != 0 && i % 2 == 0)
        arr_even_index.emplace_back(make_pair(a, i));
    }
    if (arr_odd_index.empty() && arr_even_index.empty())
      cout << 0 << '\n';
    else if (arr_even_index.size() == arr_odd_index.size())
      cout << arr_even_index.size() << '\n';
    else
      cout << -1 << '\n';
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  auto start1 = high_resolution_clock::now();
  long long int t = 1;
  while (t--) {
    solve();
  }
  auto stop1 = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop1 - start1);
  return 0;
}
