#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long c0a = 0, c1a = 0;
    long long c0b = 0, c1b = 0;
    long long count = 0;
    long long a[n], b[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    for (long long i = 0; i < n; i++) {
      b[i] = i % 2;
      if (b[i] == 1)
        c1b++;
      else if (b[i] == 0)
        c0b++;
    }
    for (long long i = 0; i < n; i++) {
      a[i] %= 2;
      if (a[i] == 1)
        c1a++;
      else if (a[i] == 0)
        c0a++;
    }
    for (long long i = 0; i < n; i++) {
      if (a[i] != b[i]) count++;
    }
    if (c1b == c1a && c0b == c0a && count != 0)
      cout << count / 2;
    else if (c1b == c1a && c0b == c0a && count == 0)
      cout << "0";
    else
      cout << -1;
    cout << endl;
  }
}
