You are given an array $a[0 \ldots n-1]$ of length $n$ which consists of non-negative integers. Note that array indices start from zero.

An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all $i$ ($0 \le i \le n - 1$) the equality $i \bmod 2 = a[i] \bmod 2$ holds, where $x \bmod 2$ is the remainder of dividing $x$ by 2.

For example, the arrays [$0, 5, 2, 1$] and [$0, 17, 0, 3$] are good, and the array [$2, 4, 6, 7$] is bad, because for $i=1$, the parities of $i$ and $a[i]$ are different: $i \bmod 2 = 1 \bmod 2 = 1$, but $a[i] \bmod 2 = 4 \bmod 2 = 0$.

In one move, you can take any two elements of the array and swap them (these elements are not necessarily adjacent).

Find the minimum number of moves in which you can make the array $a$ good, or say that this is not possible.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases in the test. Then $t$ test cases follow.

Each test case starts with a line containing an integer $n$ ($1 \le n \le 40$) — the length of the array $a$.

The next line contains $n$ integers $a_0, a_1, \ldots, a_{n-1}$ ($0 \le a_i \le 1000$) — the initial array.


-----Output-----

For each test case, output a single integer — the minimum number of moves to make the given array $a$ good, or -1 if this is not possible.


-----Example-----
Input
4
4
3 2 7 6
3
3 2 6
1
7
7
4 9 2 1 18 3 0

Output
2
1
-1
0



-----Note-----

In the first test case, in the first move, you can swap the elements with indices $0$ and $1$, and in the second move, you can swap the elements with indices $2$ and $3$.

In the second test case, in the first move, you need to swap the elements with indices $0$ and $1$.

In the third test case, you cannot make the array good.

Difficulty: EASY
Tags: Mathematics

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
import math

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b / gcd(a, b)

def bs(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return arr[mid]
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def swap(list, pos1, pos2):
	(list[pos1], list[pos2]) = (list[pos2], list[pos1])
	return list
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x0 = 0
	x1 = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if a[i] % 2 == 0:
				x0 += 1
			else:
				x1 += 1
	if x0 == x1:
		print(x0)
	else:
		print(-1)


import math
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def longestsubarray(arr, n, k):
	current_count = 0
	max_count = 0
	for i in range(0, n, 1):
		if arr[i] % k != 0:
			current_count += 1
		else:
			current_count = 0
		max_count = max(current_count, max_count)
	return max_count

def main():
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	c1 = 0
	c2 = 0
	c3 = 0
	for j in range(0, n):
		if l[j] % 2 == 0:
			c1 += 1
		if l[j] % 2 == 1:
			c2 += 1
		if l[j] % 2 == j % 2:
			l1.append(1)
		else:
			c3 += 1
			l1.append(-1)
	if c1 > n // 2 + n % 2 or c2 > n // 2:
		print(-1)
	else:
		print(c3 // 2)
t = int(input())
for i in range(0, t):
	main()


t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	ev = 0
	od = 0
	l = list(map(int, input().split()))
	if n == 1:
		if l[0] % 2 != 0:
			print(-1)
		else:
			print(0)
		continue
	for i in range(n):
		if l[i] % 2 == 0:
			if i % 2 != 0:
				ev += 1
		elif i % 2 == 0:
			od += 1
	if ev != od:
		print(-1)
	else:
		print(ev)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	r = 0
	l = 0
	for j in range(n):
		if j % 2 != a[j] % 2:
			if j % 2 == 0:
				r += 1
			else:
				l += 1
	if l != r:
		print(-1)
	else:
		print(r)


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	counter = 0
	for i in range(n):
		if a[i] % 2 == 0:
			counter += 1
	if counter == n // 2 + n % 2:
		counter = 0
		for i in range(n):
			if a[i] % 2 == 0 and i % 2 == 0:
				counter += 1
		print(n // 2 + n % 2 - counter)
	else:
		print(-1)


t = int(input())
while t > 0:
	t -= 1
	size = int(input())
	ll = list(map(int, input().strip().split()))
	ei = 0
	oi = 0
	for (index, ele) in enumerate(ll):
		ind = index % 2
		e = ele % 2
		if e == ind:
			continue
		elif ind == 0:
			ei += 1
		else:
			oi += 1
	if ei == oi:
		print(ei)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	c = []
	d = []
	for j in range(n):
		if j % 2 == 0:
			c.append(0)
		else:
			c.append(1)
		if b[j] % 2 == 0:
			d.append(0)
		else:
			d.append(1)
		j += 1
	x = 0
	y = 0
	j = 0
	while j < n:
		if c[j] == d[j]:
			pass
		elif c[j] == 1:
			x += 1
		else:
			y += 1
		j += 1
	if x == y:
		print(x)
	else:
		print(-1)


from sys import stdin
from math import ceil, gcd

def func():
	return
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	(E, O) = (0, 0)
	(ev, od) = (0, 0)
	for i in range(n):
		if arr[i] % 2 != i % 2:
			if arr[i] % 2 == 1:
				od += 1
			else:
				ev += 1
		if arr[i] % 2 == 0:
			E += 1
		else:
			O += 1
	if n % 2 == 0:
		if E == O:
			print(ev)
		else:
			print(-1)
	elif E == O + 1:
		print(ev)
	else:
		print(-1)


def tran(arr):
	o = 0
	e = o
	for i in arr:
		if i % 2 == 0:
			e = e + 1
		else:
			o = o + 1
	if len(arr) % 2 == 0 and o != e:
		return -1
	elif len(arr) % 2 == 1 and e - o != 1:
		return -1
	else:
		gd = 0
		for i in range(len(arr)):
			if i % 2 != arr[i] % 2:
				gd = gd + 1
		return int(gd / 2)
t = int(input())
ans = []
for i in range(t):
	a = int(input())
	arr = list(map(int, input().rstrip().split()))
	r = tran(arr)
	ans.append(r)
for i in ans:
	print(i)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = c = 0
	for i in range(0, len(a), 2):
		if a[i] % 2 != 0:
			b += 1
	for i in range(1, len(a), 2):
		if a[i] % 2 == 0:
			c += 1
	print(b if b == c else -1)


size = int(input())
data = []
i = 0
while i < size:
	tmp = input()
	tmp = input().split()
	data.append(list(map(int, tmp)))
	i += 1
i = 0
while i < size:
	(even, odd) = (0, 0)
	j = 0
	while j < len(data[i]):
		if j % 2 != data[i][j] % 2 and j % 2 == 0:
			even += 1
		if j % 2 != data[i][j] % 2 and j % 2 == 1:
			odd += 1
		j += 1
	if even == odd:
		print(even)
	else:
		print(-1)
	i += 1


q = int(input())
for i in range(q):
	x = int(input())
	y = input().split(' ')
	count_odd = 0
	count_even = 0
	try:
		if x > 1:
			for num in range(0, x):
				if num % 2 == 1:
					if int(y[num]) % 2 != num % 2:
						count_odd = count_odd + 1
					else:
						continue
				elif int(y[num]) % 2 != num % 2:
					count_even = count_even + 1
				else:
					continue
			count = count_odd + count_even
			if count % 2 == 0 and count_odd == count_even:
				print(int(count / 2))
			else:
				print(-1)
		elif int(y[0]) % 2 == 0:
			print(0)
		else:
			print(-1)
	except:
		print(-1)


n = int(input())
for _ in range(n):
	l = int(input())
	s = list(map(int, input().split()))
	indexList = []
	arrayList = []
	c = 0
	for i in range(l):
		iTemp = i % 2
		sTemp = s[i] % 2
		if iTemp != sTemp:
			c += 1
		indexList.append(iTemp)
		arrayList.append(sTemp)
	if indexList == arrayList:
		print(0)
	elif indexList.count(1) == arrayList.count(1) or indexList.count(0) == arrayList.count(0):
		print(c // 2)
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	e = 0
	o = 0
	c = 0
	for i in a:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
	if n % 2 == 0 and o != e or (n % 2 != 0 and o + 1 != e):
		print(-1)
	else:
		for i in range(n):
			if i % 2 == 0 and a[i] % 2 != 0 or (i % 2 != 0 and a[i] % 2 == 0):
				c += 1
		print(c // 2)
	t -= 1


for s in [*open(0)][2::2]:
	a = [int(x) % 2 for x in s.split()]
	print((sum((i % 2 ^ x for (i, x) in enumerate(a))) // 2, -1)[sum(a) != len(a) // 2])


t = int(input())
for i in range(t):
	n = int(input())
	list1 = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	for j in range(n):
		if j % 2 == 0:
			if list1[j] % 2 == 1:
				c1 = c1 + 1
		elif j % 2 == 1:
			if list1[j] % 2 == 0:
				c2 = c2 + 1
	if c1 == c2:
		print(c1)
	else:
		print('-1')
	list1.clear()


t = int(input())
for i in range(t):
	n = int(input())
	r = [0] * n
	a = list(map(int, input().split()))
	for i in range(n):
		if i % 2 == a[i] % 2:
			r[i] = 0
		else:
			r[i] = 1
	l = []
	for i in range(n):
		if r[i] == 1:
			l.append(i)
	e = 0
	o = 0
	for i in l:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
	if e == o:
		print(e)
	else:
		print(-1)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	e = 0
	o = 0
	lt = []
	l = list(map(int, input().rstrip().rsplit()))
	if n % 2 == 0:
		for i in l:
			lt.append(i % 2)
		oc = len(list(filter(lambda x: x % 2 != 0, lt)))
		if oc != n // 2:
			print(-1)
		else:
			for i in range(n):
				if i % 2 == 1 and lt[i] != 1:
					e = e + 1
			print(e)
	else:
		for i in l:
			lt.append(i % 2)
		oc = len(list(filter(lambda x: x % 2 != 0, lt)))
		if oc != n // 2:
			print(-1)
		else:
			for i in range(n):
				if i % 2 == 1 and lt[i] != 1:
					e = e + 1
			print(e)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == a[i] % 2:
			continue
		elif i % 2 == 0 and a[i] % 2 != 0:
			odd += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			even += 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	ev = 0
	od = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				ev += 1
		elif a[i] % 2 == 0:
			od += 1
	if od == ev:
		if od == 0:
			print(0)
		else:
			print(od)
	else:
		print(-1)


tc = int(input())
for ctr in range(tc):
	n = int(input())
	a = list(map(int, input().split()))
	(o, e) = (0, 0)
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 0:
				e += 1
			else:
				o += 1
	if e != o:
		print('-1')
	else:
		print(o)


for i in range(int(input())):
	c = int(input())
	a = [int(i) for i in input().split()]
	k = 0
	t = 0
	for j in range(c):
		if a[j] % 2 != j % 2 and j % 2 == 0:
			k += 1
		elif a[j] % 2 != j % 2 and j % 2 == 1:
			t += 1
	if k == t:
		print(k)
	else:
		print(-1)


import sys
input = sys.stdin.readline

def inlt():
	return list(map(int, input().split()))
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = inlt()
	cou = odd = even = 0
	while n:
		n -= 1
		if n % 2 != arr[n] % 2:
			cou += 1
			if n % 2:
				odd += 1
			else:
				even += 1
	if cou % 2 == 1:
		print(-1)
	elif odd != even:
		print(-1)
	else:
		print(int(cou / 2))


for _ in range(int(input())):
	n = int(input())
	ln = list(map(int, input().split()))
	i = 0
	oc = 0
	ec = 0
	while i < n:
		if i % 2 != ln[i] % 2:
			if ln[i] % 2 == 0:
				ec += 1
			else:
				oc += 1
		i += 1
	if oc != ec:
		print(-1)
	else:
		print(oc)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(c1, c2) = (0, 0)
	for j in range(n):
		if j % 2 != l[j] % 2:
			if j % 2 == 0:
				c1 += 1
			else:
				c2 += 1
	if c1 != c2:
		print(-1)
	else:
		print(c1)


for i in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	(e, o) = (0, 0)
	for i in range(n):
		if a[i] & 1:
			if not i & 1:
				o += 1
		elif i & 1:
			e += 1
	if e != o:
		print(-1)
	else:
		print(e)


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for y in range(n):
		if y % 2 != 0 and a[y] % 2 == 0 or (y % 2 == 0 and a[y] % 2 != 0):
			b.append(y)
	ch = 0
	nch = 0
	for y1 in range(len(b)):
		if b[y1] % 2 == 0:
			ch += 1
		else:
			nch += 1
	if nch == ch:
		print(nch)
	else:
		print(-1)


t = int(input())
for a0 in range(0, t):
	n = int(input())
	x = 0
	z = []
	o = []
	arr = list(map(int, input().split(' ')))
	for i in range(0, n):
		r = arr[i]
		r = r % 2
		if r != x and r == 0:
			z.append(i)
		if r != x and r == 1:
			o.append(i)
		x = (x + 1) % 2
	if len(z) != len(o):
		print(-1)
	else:
		print(len(z))


import math
test = int(input())
for i in range(test):
	num = int(input())
	numlist = list(map(int, input().split()))
	even = 0
	odd = 0
	ans = 0
	count = 0
	for j in range(num):
		if numlist[j] % 2 == 0:
			even += 1
		else:
			odd += 1
	if int(math.ceil(num / 2)) != even:
		ans = -1
	else:
		for j in range(num):
			if (j + numlist[j]) % 2 != 0:
				count += 1
		ans = int(count / 2)
	print(ans)


import sys
input = sys.stdin.buffer.readline
a = int(input())
for x in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	e = 0
	o = 0
	for y in range(b):
		if c[y] % 2 == 0 and y % 2 != 0:
			e += 1
		elif c[y] % 2 != 0 and y % 2 == 0:
			o += 1
	if e != o:
		print(-1)
	else:
		print(e)


t = int(input())
for g in range(0, t):
	a_len = int(input())
	a_in = input()
	a = a_in.split()
	bad = 0
	bad_num = []
	steps = 0
	chet = 0
	nechet = 0
	for h in range(0, len(a)):
		a[h] = int(a[h])
	for i in range(0, a_len):
		if i % 2 != a[i] % 2:
			bad += 1
			bad_num.append(i)
	if bad % 2 != 0:
		print('-1')
	else:
		for j in range(0, bad):
			if bad_num[j] % 2 == 0:
				chet += 1
			else:
				nechet += 1
		if nechet == chet:
			print(nechet)
		else:
			print('-1')


import sys
import math
t = int(sys.stdin.readline())
while t:
	n = int(sys.stdin.readline())
	a = list(map(int, input().split()))
	count = 0
	mise = 0
	miso = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			mise += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			miso += 1
	if mise == miso:
		print(mise)
	else:
		print(-1)
	t -= 1


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	counterodd = 0
	countereven = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 0:
				countereven += 1
			else:
				counterodd += 1
	if countereven == counterodd:
		print(countereven)
	else:
		print(-1)
t = int(input())
for i in range(t):
	solve()


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	n = sInt()
	a = lInt()
	e = 0
	o = 0
	ans = 0
	for i in range(len(a)):
		if i % 2 == 0 and a[i] % 2 == 1:
			if o == 0:
				e += 1
			else:
				ans += 1
				o -= 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			if e == 0:
				o += 1
			else:
				ans += 1
				e -= 1
	if e == 0 and o == 0:
		print(ans)
	else:
		print(-1)


for i in range(int(input())):
	odd_number = 0
	even_number = 0
	n = int(input())
	a = list(map(int, input().split()))
	y = 0
	for j in a:
		if y % 2 == 0 and j % 2 == 1:
			odd_number += 1
		elif y % 2 == 1 and j % 2 == 0:
			even_number += 1
		y += 1
	if odd_number == even_number:
		print(even_number)
	else:
		print(-1)


cas = int(input())
while cas > 0:
	n = int(input())
	o = 0
	e = 0
	lis = [i for i in input().split()]
	for i in range(0, n):
		p = int(lis[i])
		if p % 2 != i % 2:
			if p % 2:
				o = o + 1
			else:
				e = e + 1
	if o != e:
		print(-1)
	else:
		print(o)
	cas = cas - 1


time = int(input())
for i in range(time):
	n = int(input())
	ls = input().split()
	a = 0
	b = 0
	for i in range(n):
		if i % 2 == 0 and i % 2 != int(ls[i]) % 2:
			a += 1
		elif i % 2 == 1 and i % 2 != int(ls[i]) % 2:
			b += 1
	if a == b:
		print(a)
	else:
		print(-1)


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	(e, o) = (0, 0)
	x = []
	y = []
	for i in range(n):
		if l[i] & 1:
			o += 1
			if not i & 1:
				x.append(i)
		else:
			e += 1
			if i & 1:
				y.append(i)
	if o > n // 2 or e > n - n // 2:
		print('-1')
	elif len(x) != len(y):
		print('-1')
	else:
		print(len(x))
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	for i in range(0, len(b), 2):
		if b[i] % 2 != 0:
			count1 += 1
	for i in range(1, len(b), 2):
		if b[i] % 2 != 1:
			count2 += 1
	if count1 == count2:
		print(count1)
	else:
		print('-1')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	L = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if L[i] & 1 == 0:
			even += 1
		else:
			odd += 1
	count = 0
	inp_even = 0
	inp_odd = 0
	for i in range(n):
		if i & 1 == 0:
			if L[i] & 1 != 0:
				count += 1
			else:
				inp_even += 1
		elif L[i] & 1 != 1:
			count += 1
		else:
			inp_odd += 1
	val = n - inp_even - inp_odd
	val1 = even - inp_even
	val2 = odd - inp_odd
	if val & 1 == 1 or val1 != val2:
		print(-1)
	else:
		print(count // 2)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(miseven, misodd) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 == 1:
				miseven += 1
		elif a[i] % 2 == 0:
			misodd += 1
	print(miseven) if miseven == misodd else print(-1)


for t in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	(even, odd) = (0, 0)
	for i in range(len(lst)):
		if i % 2 == 0 and lst[i] % 2 != 0:
			even += 1
		elif i % 2 != 0 and lst[i] % 2 == 0:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(len(A)):
		if i % 2 == 0 and A[i] % 2 == 1:
			even += 1
		elif i % 2 == 1 and A[i] % 2 == 0:
			odd += 1
	if odd != even:
		print(-1)
	else:
		print(odd)


def main():
	num_test_cases = int(input())
	output = ''
	for t in range(0, num_test_cases):
		arr_size = int(input())
		initial_array_str = input().split()
		total_elements_grp1 = 0
		total_elements_grp2 = 0
		for (i, elem) in enumerate(initial_array_str):
			mod_value = int(elem) % 2
			mod_index = i % 2
			if mod_index != mod_value:
				if mod_index == 0:
					total_elements_grp1 += 1
				else:
					total_elements_grp2 += 1
		if total_elements_grp1 != total_elements_grp2:
			output += '-1\n'
			continue
		swaps = (total_elements_grp1 + total_elements_grp2) / 2
		output += str(int(swaps)) + '\n'
	print(output)
main()


t = int(input())
l = []
for i in range(t):
	n = int(input())
	l.append(list(map(int, input().split())))
for i in range(t):
	book = []
	for j in range(len(l[i])):
		if (j + l[i][j]) % 2 == 0:
			book.append(0)
		elif j % 2 == 0 and l[i][j] % 2 != 0:
			book.append(1)
		else:
			book.append(2)
	if book.count(1) != book.count(2):
		print(-1)
	else:
		print('%d' % book.count(1))


def readintlst():
	return list(map(int, input().split(' ')))

def readn():
	return int(input())
for _ in range(readn()):
	n = readn()
	arr = readintlst()
	odd = [x % 2 for x in arr]
	if n % 2 == 0 and sum(odd) * 2 != n:
		print(-1)
	elif n % 2 == 1 and sum(odd) != n // 2:
		print(-1)
	else:
		diff = 0
		for (i, v) in enumerate(odd):
			if i % 2 != v:
				diff += 1
		print(diff // 2)


t111 = int(input())
for _ in range(t111):
	n = int(input())
	a = list(map(int, input().split()))
	chet = 0
	nechet = 0
	for i in range(len(a)):
		if i % 2 == 0 and a[i] % 2 != 0:
			chet += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			nechet += 1
	if chet != nechet:
		print(-1)
	else:
		print(chet)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	condition = [0, 0]
	for i in arr[0::2]:
		if i % 2 == 1:
			condition[1] += 1
	if len(arr) > 1:
		for i in arr[1::2]:
			if i % 2 == 0:
				condition[0] += 1
	if condition[0] == condition[1]:
		print(condition[0])
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		if a[0] % 2 == 0:
			print(0)
		else:
			print(-1)
	else:
		d = {0: [], 1: []}
		for i in range(n):
			d[i % 2].append(a[i] % 2)
		if n % 2 == 0:
			if len(d[0]) != len(d[1]):
				print(-1)
			else:
				b = d[0][:]
				d[0].extend(d[1])
				if d[0].count(1) == d[0].count(0):
					print(b.count(1))
				else:
					print(-1)
		elif len(d[0]) != len(d[1]) + 1:
			print(-1)
		else:
			b = d[0][:]
			d[0].extend(d[1])
			if sum(d[0]) != n // 2:
				print(-1)
			else:
				print(b.count(1))


n = int(input())
for i in range(n):
	x = int(input())
	a = [int(y) for y in input().split()]
	c = 0
	d = 0
	for j in range(x):
		if j % 2 != a[j] % 2 and j % 2 == 0:
			c = c + 1
		elif j % 2 != a[j] % 2 and j % 2 == 1:
			d = d + 1
	if c != d:
		print('-1')
	else:
		print(d)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	a = input()
	x = a.split(' ')
	k1 = 0
	k2 = 0
	if n % 2 == 0:
		k3 = n / 2
		k4 = k3
	else:
		k3 = n // 2
		k4 = k3 + 1
	for j in range(n):
		if int(x[j]) % 2 == 0:
			k1 += 1
		else:
			k2 += 1
	if k1 != k4 or k2 != k3:
		ans.append(-1)
		continue
	k = 0
	for j in range(n):
		if j % 2 != int(x[j]) % 2:
			k += 1
	ans.append(k // 2)
for i in range(t):
	print(ans[i])


for t in range(int(input())):
	l = int(input())
	nums = input().split()
	missi = []
	for i in range(l):
		nums[i] = int(nums[i])
		if nums[i] % 2 != i % 2:
			missi.append(i)
	if len(missi) == 0:
		print(0)
	elif len(missi) % 2 != 0:
		print(-1)
	else:
		evenn = 0
		eveni = 0
		for i in missi:
			if nums[i] % 2 == 0:
				evenn += 1
			if i % 2 == 0:
				eveni += 1
		if eveni == int(len(missi) / 2):
			print(eveni)
		else:
			print(-1)


t = int(input())
for i in range(t):
	s = int(input())
	l = list(map(int, input().split()))
	cnt1 = 0
	cnt2 = 0
	cnt3 = 0
	for i in range(s):
		if l[i] % 2 == 0:
			cnt1 += 1
		else:
			cnt2 += 1
		if l[i] % 2 == i % 2:
			cnt3 += 1
	if cnt1 == cnt2 and s % 2 == 0:
		print((s - cnt3) // 2)
	elif cnt1 - cnt2 == 1 and s % 2 == 1:
		print((s - cnt3) // 2)
	else:
		print(-1)


nb_cases = int(input())
while nb_cases > 0:
	nb_cases -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	incorrect = [0, 0]
	for x in range(n):
		if x % 2 == 0 and a[x] % 2 == 1:
			incorrect[0] += 1
		if x % 2 == 1 and a[x] % 2 == 0:
			incorrect[1] += 1
	if incorrect[0] == incorrect[1]:
		print(incorrect[0])
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		if l[0] % 2 == 0:
			print('0')
		else:
			print('-1')
	else:
		o = 0
		e = 0
		c = 0
		for i in range(n):
			if l[i] % 2 == 0:
				e += 1
			elif l[i] % 2 == 1:
				o += 1
			if l[i] % 2 != i % 2:
				c += 1
		xo = n // 2
		xe = (n + 1) // 2
		if xo == o and xe == e and (c % 2 == 0):
			print(c // 2)
		else:
			print('-1')


for i in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	o = 0
	e = 0
	for j in range(n):
		if j % 2 == 0:
			if l1[j] % 2 != 0:
				o += 1
			else:
				continue
		if j % 2 != 0:
			if l1[j] % 2 == 0:
				e += 1
			else:
				continue
	if o == e:
		print(o)
	else:
		print(-1)


n = int(input())
for xy in range(n):
	t = int(input())
	ql = [int(x) for x in input().split()]
	even = 0
	odd = 0
	for ab in range(t):
		if ab % 2 != ql[ab] % 2 and ab % 2 == 0:
			even += 1
		if ab % 2 != ql[ab] % 2 and ab % 2 == 1:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	mto = 0
	mte = 0
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 == 1:
			mto += 1
		elif i % 2 == 1 and l[i] % 2 == 0:
			mte += 1
	if mto == mte:
		print(mto)
	else:
		print('-1')


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree1:

	def __init__(self, data, default=9999999, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l = [l[i] % 2 - i % 2 for i in range(n)]
	if sum(l) != 0:
		print(-1)
	else:
		ans = 0
		for j in l:
			if j != 0:
				ans += 1
		print(ans // 2)


n = int(input())
for i in range(n):
	t = int(input())
	l = list(map(int, input().split()))
	om = 0
	em = 0
	for j in range(t):
		if j % 2 == l[j] % 2:
			continue
		elif j % 2 == 0:
			em += 1
		elif j % 2 == 1:
			om += 1
	if em == om:
		print(em)
	else:
		print('-1')


for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(x, y) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			if l[i] % 2 == 1:
				x = x + 1
		elif l[i] % 2 == 0:
			y = y + 1
	if x != y:
		print(-1)
	else:
		print(x)


k = int(input())
for h in range(k):
	n = int(input())
	mas = [int(x) for x in input().split()]
	(t1, t2) = (0, 0)
	for i in range(len(mas)):
		if i % 2 != mas[i] % 2:
			if mas[i] % 2 == 1:
				t1 += 1
			if mas[i] % 2 == 0:
				t2 += 1
	if t1 == t2:
		print(t1)
	else:
		print(-1)


t = int(input())
for i in range(0, t):
	n = int(input())
	L = list(map(int, input().split()))
	count = 0
	oddicount = 0
	evenicount = 0
	s = set()
	for i in range(0, n):
		if (L[i] - i) % 2 != 0:
			count += 1
			if i % 2 == 0:
				evenicount += 1
			else:
				oddicount += 1
			s.add(L[i])
	if count == 0:
		print(0)
	elif oddicount == evenicount:
		print(oddicount)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	count_odd = 0
	count_even = 0
	count_irr = 0
	for (j, aa) in enumerate(a):
		if aa % 2 == 0:
			count_even += 1
			if j % 2 != 0:
				count_irr += 1
		else:
			count_odd += 1
			if j % 2 == 0:
				count_irr += 1
	if n % 2 == 0:
		if count_even != count_odd:
			print(-1)
		else:
			print(int(count_irr / 2))
	elif count_even != count_odd + 1:
		print(-1)
	else:
		print(int(count_irr / 2))


def solve(arr):
	n = len(arr)
	cnt = [0, 0]
	odd_mismatches = 0
	for (i, v) in enumerate(arr):
		cnt[v % 2] += 1
		if i % 2 == 1 and v % 2 == 0:
			odd_mismatches += 1
	if cnt[0] - n % 2 != cnt[1]:
		return -1
	return odd_mismatches
for _ in range(int(input())):
	n = int(input())
	(*arr,) = map(int, input().split())
	print(solve(arr))


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	cnte = 0
	cnto = 0
	for i in range(n):
		if arr[i] % 2 != i % 2 and i % 2 == 0:
			cnte += 1
		elif arr[i] % 2 != i % 2 and i % 2 != 0:
			cnto += 1
	if cnte != cnto:
		print(-1)
	else:
		print(cnte)

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	o = 0
	e = 0
	for j in range(0, n):
		if j % 2 != l[j] % 2:
			if j % 2 == 0:
				e += 1
			else:
				o += 1
	if e == o:
		print(e)
	else:
		print('-1')


def solve(n, arr):
	arr2 = []
	cnt = 0
	cnt0 = 0
	cnt1 = 0
	if n % 2 == 0:
		cnt0 = n // 2
		cnt1 = cnt0
	else:
		cnt0 = n // 2 + 1
		cnt1 = n // 2
	for i in range(0, n):
		arr2.append(arr[i] % 2)
	if arr2.count(0) != cnt0 and arr2.count(1) != cnt1:
		print(-1)
		return
	else:
		for j in range(n):
			if arr2[j] != j % 2:
				cnt += 1
		print(cnt // 2)
test = int(input())
while test != 0:
	n1 = int(input())
	arr1 = list(map(int, input().split(' ')))
	solve(n1, arr1)
	test -= 1


n = int(input())
for i in range(n):
	l = input()
	b = input().split()
	e = u = 0
	for i in range(int(l)):
		if int(b[i]) % 2 == 0 and int(i) % 2 == 1:
			e += 1
		elif int(b[i]) % 2 == 1 and int(i) % 2 == 0:
			u += 1
	if u == e:
		print(int(u))
	else:
		print(-1)


rr = lambda : input()
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))
INF = float('inf')

def solve(n, arr):
	odd = 0
	even = 0
	mismatch = 0
	for (i, v) in enumerate(arr):
		if v & 1:
			odd += 1
			if not i & 1:
				mismatch += 1
		else:
			even += 1
			if i & 1:
				mismatch += 1
	wanteven = n // 2 + +(n % 2 == 0)
	wantodd = n // 2
	if odd != wantodd and even != wanteven:
		return -1
	if mismatch & 1:
		return -1
	return mismatch // 2
t = int(input())
for _ in range(t):
	n = rri()
	arr = rrm()
	print(solve(n, arr))


def solve(arr, n):
	(odd, even) = (0, 0)
	for each in arr:
		if each & 1:
			odd += 1
		else:
			even += 1
	if n & 1 == 0 and odd == even or (n & 1 and odd + 1 == even):
		count = 0
		for i in range(n):
			if arr[i] & 1 == i & 1:
				continue
			count += 1
		return count // 2
	return -1

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		ans = solve(arr, n)
		print(ans)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	bad = [0, 0]
	for (i, x) in enumerate(map(int, input().split())):
		if x % 2 != i % 2:
			bad[x % 2] += 1
	if bad[0] != bad[1]:
		print(-1)
	else:
		print(bad[0])


for i in range(int(input())):
	a = input()
	x = [int(x) for x in input().split()]
	cnt1 = cnt2 = 0
	for i in range(len(x)):
		if i % 2 == 0:
			if x[i] % 2 != 0:
				cnt1 += 1
		elif x[i] % 2 == 0:
			cnt2 += 1
	print(-1 if cnt1 != cnt2 else cnt1)


p = int(input())
m = []
k = -1
for t in range(p):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	d = 0
	l = 0
	for i in range(n):
		if a[i] % 2 != i % 2 and a[i] % 2 == 0:
			c += 1
		elif a[i] % 2 != i % 2 and a[i] % 2 == 1:
			d += 1
	if c == d:
		if (c + d) % 2 == 0:
			m.append(c)
	else:
		m.append(k)
for i in range(len(m)):
	print(m[i])


def even_string(l):
	(even, odd) = (0, 0)
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] % 2 == 1:
				even += 1
		elif i % 2 == 1:
			if l[i] % 2 == 0:
				odd += 1
	if even != odd:
		return -1
	return even
for _ in range(int(input())):
	n = int(input())
	parity = list(map(int, input().split()))
	print(even_string(parity))


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = [int(x) for x in input().split()]
	xx = 0
	yy = 0
	for i in range(0, n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				xx += 1
		elif a[i] % 2 != 1:
			yy += 1
	if max(xx, yy) == 0:
		print(0)
	else:
		(cc, dd) = (max(xx, yy), min(xx, yy))
		if cc == dd:
			print(cc)
		else:
			print(-1)


import sys
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	l = RI()
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 == l[i] % 2:
			continue
		elif i % 2 == 0:
			even += 1
		else:
			odd += 1
	if odd == 0 and even == 0:
		print(0)
	elif odd == even:
		print(odd)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	count = 0
	sol = []
	ev = 0
	od = 0
	for i in range(len(ar)):
		if i % 2 != ar[i] % 2:
			count += 1
			sol.append(i)
	for ind in sol:
		if ar[ind] % 2 == 0:
			ev += 1
		else:
			od += 1
	if count % 2 == 0 and ev == od:
		print(int(count / 2))
	elif count == 0:
		print(0)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	(e, o) = (0, 0)
	for i in range(n):
		if i % 2 != l[i] % 2 and i % 2 == 0:
			o += 1
		elif i % 2 != l[i] % 2 and i % 2 == 1:
			e += 1
	if e == o:
		print(o)
	else:
		print('-1')


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c_odd = 0
	c_even = 0
	for i in range(len(l)):
		if i % 2 != l[i] % 2 and i % 2 == 0:
			c_odd += 1
		if i % 2 != l[i] % 2 and i % 2 != 0:
			c_even += 1
	if c_odd == c_even and (c_odd + c_even) % 2 == 0:
		print(c_odd)
	else:
		print(-1)


arr = []
t = int(input())
for _ in range(t):
	n = int(input())
	arr.append(list(map(int, input().split())))
for arr in arr:
	even = 0
	odd = 0
	for n in range(len(arr)):
		if n % 2 != arr[n] % 2:
			if arr[n] % 2 == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print('-1')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	o = 0
	e = 0
	c = 0
	for i in range(n):
		if i % 2 != 0 and a[i] % 2 == 0 or (i % 2 == 0 and a[i] % 2 != 0):
			c += 1
		if a[i] % 2 == 0:
			e += 1
		else:
			o += 1
	if n % 2 != 0:
		if e == n // 2 + 1 and o == n // 2:
			print(c // 2)
		else:
			print(-1)
	elif e == n // 2 and o == n // 2:
		print(c // 2)
	else:
		print(-1)


def solve(v):
	even = 0
	odd = 0
	for (i, a) in enumerate(v):
		if i % 2 == 0 and a % 2 == 1:
			even += 1
		elif i % 2 == 1 and a % 2 == 0:
			odd += 1
	return even if even == odd else -1
n = int(input())
for i in range(n):
	l = int(input())
	v = list(map(int, input().strip().split()))
	if l != len(v):
		raise Error
	print(solve(v))


t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	(c1, c2) = (0, 0)
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				c1 = c1 + 1
			else:
				c2 = c2 + 1
	print(c1 if c1 == c2 else -1)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		swap = swap2 = 0
		for i in range(n):
			if i % 2 == 1:
				if a[i] % 2 == 0:
					swap += 1
			elif a[i] % 2 == 1:
				swap2 += 1
		if swap == swap2:
			print(swap)
		else:
			print(-1)
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if arr[i] % 2 == 0:
				e += 1
			else:
				o += 1
	if e != o:
		print(-1)
	else:
		print(o)


n = int(input())
final = []
for i in range(n):
	k = int(input())
	arr = list(map(int, input().split()))
	wrongodd = 0
	wrongeven = 0
	for i in range(k):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				wrongeven += 1
			else:
				wrongodd += 1
	if wrongeven == wrongodd:
		final.append(wrongodd)
	else:
		final.append(-1)
for i in range(n):
	print(final[i])


def fun(a):
	odd = 0
	even = 0
	for i in range(0, len(a), 2):
		if a[i] % 2 == 1:
			odd += 1
	for i in range(1, len(a), 2):
		if a[i] % 2 == 0:
			even += 1
	if odd != even:
		return -1
	else:
		return odd
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(fun(a))


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))[:n]
	count = 0
	c1 = 0
	c2 = 0
	x = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 == 0:
				count += 1
		if i % 2 == 1:
			if a[i] % 2 == 1:
				count += 1
		if a[i] % 2 == 0:
			c1 += 1
		if a[i] % 2 == 1:
			c2 += 1
	if count == n:
		print(0)
		continue
	if n % 2 == 0:
		if c1 != c2:
			print(-1)
			continue
	if n % 2 == 1:
		if c1 - 1 != c2:
			print(-1)
			continue
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 == 0:
				continue
			for j in range(i + 1, n, 2):
				if a[j] % 2 == 0:
					temp = a[i]
					a[i] = a[j]
					a[j] = temp
					x += 1
					f = 1
					break
		elif i % 2 == 1:
			if a[i] % 2 == 1:
				continue
			for j in range(i + 1, n, 2):
				if a[j] % 2 == 1:
					temp = a[i]
					a[i] = a[j]
					a[j] = temp
					x += 1
					f = 1
					break
	print(x)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		n = N()
		arr = RLL()
		cp = [i % 2 for i in range(n)]
		am = [i % 2 for i in arr]
		if Counter(cp) != Counter(am):
			print(-1)
		else:
			dif = 0
			for i in range(n):
				if cp[i] != am[i]:
					dif += 1
			print(dif // 2)
main()


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 == 1:
			if arr[i] % 2 == 1:
				continue
			else:
				odd += 1
		elif arr[i] % 2 == 0:
			continue
		else:
			even += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	d = 0
	d2 = 0
	for j in range(n):
		if j % 2 != a[j] % 2 and j % 2 == 0:
			d += 1
		elif j % 2 != a[j] % 2 and j % 2 != 0:
			d2 += 1
	if d == d2:
		ans.append(int(d))
	else:
		ans.append(-1)
for x in ans:
	print(x)


import math as mt
import sys, string
input = sys.stdin.readline
from collections import defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	n = I()
	l = L()
	c = 0
	o = 0
	e = 0
	for i in range(n):
		if l[i] % 2 == 0:
			e += 1
		if l[i] % 2 == 1:
			o += 1
		if i % 2 != l[i] % 2:
			c += 1
	if n % 2 == 1:
		if e - o != 1:
			print(-1)
		elif c % 2 == 0:
			print(c // 2)
		else:
			print(-1)
	elif e != o:
		print(-1)
	elif c % 2 == 0:
		print(c // 2)
	else:
		print(-1)


from sys import stdin
import math

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	n = int(inp())
	a = [int(x) for x in inp().split()]
	badOdd = 0
	badEven = 0
	for i in range(n):
		if a[i] % 2 == 0:
			if i % 2 == 1:
				badEven += 1
		if a[i] % 2 == 1:
			if i % 2 == 0:
				badOdd += 1
	if badEven == badOdd:
		print(badEven)
	else:
		print(-1)


o = int(input())
for _ in range(o):
	n = int(input())
	A = list(map(int, input().split(' ')))
	count = 0
	for i in range(n):
		if A[i] % 2 != i % 2:
			for j in range(i + 1, n):
				if j % 2 != i % 2 and j % 2 != A[j] % 2:
					(A[i], A[j]) = (A[j], A[i])
					count += 1
					break
	done = False
	for i in range(n):
		if A[i] % 2 != i % 2:
			print(-1)
			done = True
			break
	if not done:
		print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	count = [0] * 2
	for i in range(n):
		if i % 2 != l[i] % 2:
			count[i % 2] += 1
	if count[0] == count[1]:
		print(count[0])
	else:
		print(-1)


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	cnt = []
	for i in a:
		cnt.append(i & 1)
	odd = cnt.count(1)
	even = cnt.count(0)
	if n & 1 and even != odd + 1:
		print(-1)
		continue
	elif n & 1 == 0 and even != odd:
		print(-1)
		continue
	else:
		ans = 0
		for i in range(n):
			if i & 1 != cnt[i]:
				ans += 1
		print(ans // 2)


for _ in range(int(input())):
	n = int(input())
	even = 0
	odd = 0
	l = list(map(int, input().split()))
	for i in range(n):
		if i % 2 != l[i] % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if odd == even:
		print(even)
	else:
		print(-1)


t = int(input())
for veces in range(t):
	n = int(input())
	vec = list(map(int, input().rstrip().split()))
	IncorrectosPar = 0
	IncorrectosImpar = 0
	for i in range(len(vec)):
		if i % 2 == 1 and vec[i] % 2 == 0:
			IncorrectosImpar = IncorrectosImpar + 1
		elif i % 2 == 0 and vec[i] % 2 == 1:
			IncorrectosPar = IncorrectosPar + 1
	if IncorrectosPar == IncorrectosImpar:
		print(IncorrectosPar)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	s = [int(i) for i in input().split()]
	cnt = 0
	cntc = 0
	for j in range(n):
		if s[j] % 2 != j % 2:
			if s[j] % 2 == 0:
				cntc += 1
			else:
				cnt += 1
	if cnt == cntc:
		print(cnt)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		if l[0] % 2 == 0:
			print('0')
		else:
			print('-1')
	else:
		o = 0
		e = 0
		c = 0
		for i in range(n):
			if l[i] % 2 == 0:
				e += 1
			elif l[i] % 2 == 1:
				o += 1
			if l[i] % 2 != i % 2:
				c += 1
		xo = n // 2
		xe = (n + 1) // 2
		if xo == o and xe == e and (c % 2 == 0):
			print(c // 2)
		else:
			print('-1')


for ii in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	cc = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			c += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			cc += 1
	if c == cc:
		print(c)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0:
			if ar[i] % 2 != 0:
				even += 1
		elif ar[i] % 2 != 1:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


i = int(input())
for _ in range(i):
	n = int(input())
	l1 = list(map(int, input().split()))
	odd = 0
	even = 0
	for x in range(n):
		if x % 2 == 0 and l1[x] % 2 != 0:
			even += 1
		elif x % 2 == 1 and l1[x] % 2 != 1:
			odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


from sys import stdin, stdout
import math, collections

def solve():
	cases = int(input())
	for case in range(1, cases + 1):
		b = input()
		a = [int(n) for n in input().split()]
		c = 0
		n = 0
		for (i, e) in enumerate(a):
			if i % 2 == 0 and e % 2 == 1:
				n += 1
			if i % 2 == 1 and e % 2 == 0:
				c += 1
		if c == n:
			print(c)
		else:
			print(-1)
solve()


t = int(input())
for i in range(t):
	n = int(input())
	ai = input().split()
	good = bad = 0
	for i in range(n):
		if int(ai[i]) % 2 == 0:
			if i % 2 == 0:
				good += 1
			else:
				bad += 1
	if good + bad == (n + 1) // 2:
		print(bad)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	if n % 2 == 0:
		if even != odd:
			print(-1)
		else:
			count = 0
			for i in range(n):
				if i % 2 == arr[i] % 2:
					pass
				else:
					count += 1
			print(count // 2)
	elif even != odd + 1:
		print(-1)
	else:
		count = 0
		for i in range(n):
			if i % 2 == arr[i] % 2:
				pass
			else:
				count += 1
		print(count // 2)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	y = 0
	for i in range(0, len(a)):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				x = x + 1
		elif a[i] % 2 == 0:
			y = y + 1
	if x == y:
		print(x)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	wrong = [0, 0]
	for i in range(n):
		if i % 2 != a[i] % 2:
			wrong[i % 2] += 1
	if wrong[0] != wrong[1]:
		print(-1)
	else:
		print(wrong[0])


n = input()
for _ in range(0, int(n)):
	chet = 0
	ans = 0
	l = input()
	cur = input().split()
	for i in range(0, int(l)):
		if int(cur[i]) % 2 != i % 2:
			ans += 1
			if int(cur[i]) % 2 == 1:
				chet += 1
			else:
				chet -= 1
	if chet != 0:
		print(-1)
	else:
		print(int(ans / 2))


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import string as st
import heapq

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def main():
	try:
		n = I()
		l = list(In())
		ans = 0
		ans1 = 0
		for x in range(n):
			if x & 1 != 1 and l[x] & 1 == 1:
				ans += 1
			elif l[x] & 1 != 1 and x & 1 == 1:
				ans1 += 1
			else:
				continue
		if ans1 == ans:
			print(ans)
		else:
			print(-1)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


t = int(input())
for hh in range(0, t):
	n = int(input())
	a = [int(x) for x in input().split()]
	neededbase0 = 0
	neededbase1 = 0
	for i in range(0, n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				neededbase0 += 1
		elif a[i] % 2 != 1:
			neededbase1 += 1
	if max(neededbase0, neededbase1) == 0:
		print(0)
	else:
		(mx, mn) = (max(neededbase0, neededbase1), min(neededbase0, neededbase1))
		if mx == mn:
			print(mx)
		else:
			print(-1)


n = int(input())
for i in range(n):
	t = int(input())
	l = list(map(int, input().split(' ')))
	c = 0
	c1 = 0
	for i in range(t):
		if i % 2 != l[i] % 2 and i % 2 == 0:
			c1 += 1
		elif i % 2 != l[i] % 2 and i % 2 == 1:
			c += 1
	if c != c1:
		print(-1)
	else:
		print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(a) for a in input().split()]
	e = 0
	o = 0
	for x in range(n):
		if x % 2 == 0:
			if a[x] % 2 == 0:
				continue
			else:
				e = e + 1
		elif a[x] % 2 == 1:
			continue
		else:
			o = o + 1
	if e == o:
		print(e)
	else:
		print('-1')


n = int(input())
for i in range(n):
	a = int(input())
	L = list(map(lambda x: x % 2, list(map(int, input().split()))))
	X = []
	for i in range(len(L)):
		X.append(i % 2)
	counte = 0
	counto = 0
	for i in range(len(L)):
		if L[i] != X[i]:
			if L[i] == 0:
				counte += 1
			else:
				counto += 1
	if counte == counto:
		print(counte)
	else:
		print(-1)


def swapPositions(list1, pos1, pos2):
	(list1[pos1], list1[pos2]) = (list1[pos2], list1[pos1])
	return list1
cases = int(input(''))
output = []
for case in range(cases):
	list1 = []
	flag = 0
	counter = 0
	size = int(input(''))
	x = input('').split()
	for c in range(size):
		list1.append(int(x[c]))
	for c in range(size + 1):
		if size == 1:
			if list1[0] % 2 == 0 % 2:
				output.append(0)
				break
			else:
				output.append(-1)
				break
		elif flag == 1:
			break
		elif c == size:
			output.append(counter)
			break
		elif c % 2 == list1[c] % 2:
			continue
		else:
			y = c
			for i in range(y + 1, size + 1):
				if i == size:
					flag = 1
					output.append(-1)
					break
				if c % 2 == list1[i] % 2 and list1[y] % 2 == i % 2:
					list1 = swapPositions(list1, y, i)
					counter += 1
					break
print(*output, sep='\n')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	odds = 0
	evens = 0
	for j in range(len(a)):
		if j % 2 != a[j] % 2 and j % 2 == 0:
			odds += 1
		elif j % 2 != a[j] % 2 and j % 2 == 1:
			evens += 1
	if odds == evens:
		print(odds)
	else:
		print(-1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	a = [int(x) for x in s.split(' ')]
	even = 0
	odd = 0
	count = 0
	for item in a:
		if item % 2 == 0 and count % 2 == 1:
			even += 1
		elif item % 2 == 1 and count % 2 == 0:
			odd += 1
		count += 1
	if even == odd:
		print(even)
	else:
		print(-1)


for _ in range(int(input())):
	alen = int(input())
	arr = list(map(int, input().split()))
	eF = 0
	oF = 0
	for i in range(alen):
		if i % 2 == 0 and arr[i] % 2 != 0:
			eF += 1
		elif i % 2 == 1 and arr[i] % 2 != 1:
			oF += 1
	if oF == eF:
		print(oF)
	else:
		print(-1)


import sys, math
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ch = 0
	nech = 0
	for i in a:
		if i % 2 == 0:
			ch += 1
		else:
			nech += 1
	if ch == nech or ch - 1 == nech:
		ans = 0
		for i in range(n):
			if a[i] % 2 != i % 2:
				ans += 1
		print(ans // 2)
	else:
		print(-1)


def fun(arr, n):
	even = 0
	odd = 0
	if n == 1 and arr[0] % 2 != 0:
		return -1
	for i in range(0, n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			even = even + 1
		if i % 2 != 0 and arr[i] % 2 == 0:
			odd = odd + 1
	if even != odd:
		return -1
	return odd
for i in range(0, int(input())):
	n = int(input())
	val = [int(x) for x in input().split()]
	print(fun(val, n))


t = int(input())
for i in range(t):
	n = int(input())
	num = list(map(int, input().split()))
	(o, e, p, ep, op) = (0, 0, 0, 0, 0)
	for j in range(len(num)):
		if num[j] % 2 == 0 and j % 2 != 0:
			e = e + 1
		elif num[j] % 2 != 0 and j % 2 == 0:
			o = o + 1
		elif num[j] % 2 == 0 and j % 2 == 0:
			ep = ep + 1
		elif num[j] % 2 != 0 and j % 2 != 0:
			op = op + 1
	if len(num) % 2 == 0:
		if e + ep <= len(num) // 2 and o + op <= len(num) // 2:
			print(max(e, o))
		else:
			print(-1)
	elif e + ep <= len(num) // 2 + 1 and o + op <= len(num) // 2:
		print(max(e, o))
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = 0
	b = 0
	for i in range(0, n, 2):
		if l[i] % 2 != 0:
			a += 1
	for i in range(1, n, 2):
		if l[i] % 2 == 0:
			b += 1
	if b == a:
		print(b)
	else:
		print(-1)


import sys, math, bisect
from collections import Counter, defaultdict as dd

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def l():
	return list(sp())

def strl():
	return list(strsp())

def sp():
	return map(int, data().split())

def strsp():
	return map(str, data().split())
for _ in range(int(data())):
	n = int(data())
	a = l()
	(even, odd, b) = (0, 0, 0)
	for i in range(n):
		if a[i] % 2 == i % 2:
			b += 1
		elif a[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	if even != odd:
		print(-1)
	elif b == n:
		print(0)
	else:
		print(even)


for _ in range(int(input())):
	a = int(input())
	s = [int(i) for i in input().split()]
	ch = 0
	nh = 0
	for i in range(a):
		if i % 2 != s[i] % 2:
			if i % 2 == 0:
				ch += 1
			else:
				nh += 1
	print(ch if nh == ch else -1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(ec, nc) = (0, 0)
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 0:
				ec += 1
			else:
				nc += 1
	if ec == nc:
		print(ec)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if not i & 1:
			if l[i] & 1:
				even += 1
		elif not l[i] & 1:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


from collections import defaultdict as dfd
import math
import sys
import heapq

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def main():
	for _ in range(int(input())):
		N = II()
		A = LI()
		even = 0
		odd = 0
		for i in range(len(A)):
			if i % 2 == 0 and A[i] % 2 != 0:
				even += 1
			elif i % 2 != 0 and A[i] % 2 == 0:
				odd += 1
		if even == odd:
			print(even)
		else:
			print(-1)
main()


t = int(input())
for i in range(t):
	cnt = 0
	n = int(input())
	l = list(map(int, input().split()))
	l1 = [i % 2 for i in range(n)]
	l2 = [i % 2 for i in l]
	for j in range(n):
		if l1[j] != l2[j]:
			cnt += 1
	if l1.count(1) == l2.count(1) and l1.count(0) == l2.count(0):
		print(cnt // 2)
	else:
		print('-1')


n = int(input())
for i in range(0, n):
	y = int(input())
	x = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	for j in range(0, y):
		if j % 2 == 0:
			if x[j] % 2 == 0:
				yeet = 1
			else:
				count1 += 1
		elif x[j] % 2 != 0:
			yeet = 1
		else:
			count2 += 1
	if count1 == count2:
		print(count1)
	else:
		print('-1')


def f(n):
	return int(n) % 2
for _ in range(int(input())):
	n = int(input())
	l = list(map(f, input().split()))
	cl = []
	c = 0
	for i in range(n):
		if c == 0:
			cl.append(0)
			c += 1
		else:
			cl.append(1)
			c -= 1
	ce = 0
	co = 0
	for i in range(n):
		if l[i] != cl[i]:
			if cl[i] == 0:
				ce += 1
			else:
				co += 1
	if ce == co:
		print(ce)
	else:
		print(-1)


test_case = int(input())
for i in range(test_case):
	n = int(input())
	numbers = list(map(int, input().split()))
	a = b = 0
	for (index, num) in enumerate(numbers):
		if index % 2 != num % 2:
			if index % 2 == 0:
				a += 1
			else:
				b += 1
	if a != b:
		print(-1)
	else:
		print(a)


def read_int():
	return int(input())

def read_string_array():
	for s in input().split():
		yield s

def read_int_array():
	for s in read_string_array():
		yield int(s)

def read_line():
	return input()

def solve(a):
	even_mismatch = 0
	odd_mismatch = 0
	for (i, item) in enumerate(a):
		if i % 2 != item % 2:
			if i % 2:
				odd_mismatch += 1
			else:
				even_mismatch += 1
	if odd_mismatch == even_mismatch:
		return odd_mismatch
	else:
		return -1
T = read_int()
for _ in range(T):
	N = read_int()
	A = read_int_array()
	print(solve(A))


t = int(input())
while t > 0:
	even = 0
	odd = 0
	n = int(input())
	lst = list(map(int, input().strip().split(' ')))
	for a in range(n):
		b = lst[a]
		if a % 2 == b % 2:
			continue
		elif a % 2 == 1:
			odd += 1
		else:
			even += 1
	if even == odd:
		print(even)
	else:
		print(-1)
	t -= 1


for _ in range(int(input())):
	N = int(input())
	L = list(map(int, input().split()))
	(diff, odd, even) = (0, 0, 0)
	for i in range(N):
		if L[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if i % 2 != L[i] % 2:
			diff += 1
	if N // 2 != odd:
		print(-1)
	else:
		print(diff // 2)


from sys import stdin

def readline():
	return stdin.readline()
tests = int(readline())

def solve(n, a):
	e = 0
	o = 0
	for i in range(0, n):
		if i % 2 == 0 and a[i] % 2 != 0:
			e += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			o += 1
	if e != o:
		return -1
	return e
for t in range(0, tests):
	n = int(readline().rstrip('\n'))
	a = list(map(int, readline().split(' ')))
	print(solve(n, a))


t = int(input())
for f in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c1 = 0
	c0 = 0
	wc1 = wc0 = 0
	need = n // 2
	for i in range(n):
		if i % 2 == 0:
			if l[i] % 2 == 1:
				wc1 += 1
			else:
				c0 += 1
		elif l[i] % 2 == 0:
			wc0 += 1
		else:
			c1 += 1
	if c1 + wc1 == need and wc0 + c0 == n - need:
		print((wc1 + wc0) // 2)
	else:
		print(-1)


from sys import stdin

def ip():
	return [int(i) for i in stdin.readline().split()]

def sp():
	return [str(i) for i in stdin.readline().split()]

def solve():
	n = int(input())
	A = ip()
	(e, o) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and A[i] % 2 != 0:
			o += 1
		elif i % 2 == 1 and A[i] % 2 != 1:
			e += 1
	if e != o:
		return -1
	else:
		return e
t = int(input())
for _ in range(t):
	print(solve())


import math
t = int(input())
for g in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	ans = 0
	a = 0
	f = 0
	if n == 1 and A[0] % 2 != 0:
		print('-1')
		continue
	for i in range(n):
		a = -1
		if i % 2 != 0 and A[i] % 2 == 0:
			for j in range(0, n):
				if j % 2 == 0 and A[j] % 2 != 0:
					a = 1
					ans += 1
					(A[i], A[j]) = (A[j], A[i])
					break
			if a == -1:
				f = 1
				print('-1')
				break
		elif i % 2 == 0 and A[i] % 2 != 0:
			for j in range(0, n):
				if j % 2 != 0 and A[j] % 2 == 0:
					a = 1
					ans += 1
					(A[i], A[j]) = (A[j], A[i])
					break
			if a == -1:
				f = 1
				print('-1')
				break
	if f == 1:
		continue
	print(ans)


t = int(input())
N = [None] * t
for k in range(t):
	n = int(input())
	m = list(map(int, input().split()))
	bad_odd = 0
	bad_even = 0
	for i in range(len(m)):
		if i % 2 != m[i] % 2 and i % 2 == 1:
			bad_odd += 1
		elif i % 2 != m[i] % 2 and i % 2 == 0:
			bad_even += 1
	if bad_odd == bad_even:
		N[k] = bad_odd
	else:
		N[k] = -1
for k in range(t):
	print(N[k])


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ecount = 0
	ocount = 0
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 == 0:
			continue
		elif i % 2 == 1 and l[i] % 2 == 1:
			continue
		elif l[i] % 2 == 0:
			ecount += 1
		else:
			ocount += 1
	if ecount == 0 and ocount == 0:
		print('0')
	elif ecount == ocount:
		print(ecount)
	else:
		print('-1')


def solve(n, d):
	big = float('inf')
	small = float('-inf')
	ev = 0
	od = 0
	for i in range(n):
		if d[i] % 2 == 0 and i % 2 == 1:
			ev += 1
		elif d[i] % 2 == 1 and i % 2 == 0:
			od += 1
	if ev == od:
		return ev
	return -1

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		d = input()
		d = [int(i) for i in d.split()]
		ans = solve(n, d)
		print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(ev, od, c) = (0, 0, 0)
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 == 0 or (i & 1 and l[i] & 1):
			c += 1
	if c == n:
		print(0)
		continue
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 != 0:
			ev += 1
		elif i & 1 and l[i] % 2 == 0:
			od += 1
	if ev != od:
		print(-1)
	else:
		print(ev)


def steps_to_good(a):
	(even, odd) = (0, 0)
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2 == 1:
				even += 1
			else:
				odd += 1
	if even == odd:
		return even
	else:
		return -1
t = int(input())
for it in range(t):
	n = int(input())
	a = [int(s) for s in input().split()]
	print(steps_to_good(a))


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, input().strip().split()))
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 != s[i] % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if even != odd:
		print(-1)
	else:
		print(even)


t = int(input())
for qwe in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	chet = 0
	nech = 0
	for i in range(n):
		if a[i] % 2 == 1 and i % 2 == 0:
			nech += 1
		elif a[i] % 2 == 0 and i % 2 == 1:
			chet += 1
	if chet == nech:
		print(chet)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dic = {'good': 0, 'obad': 0, 'ebad': 0}
	for i in range(n):
		if a[i] % 2 == i % 2:
			dic['good'] += 1
		elif a[i] % 2 == 1:
			dic['ebad'] += 1
		else:
			dic['obad'] += 1
	if dic['obad'] == dic['ebad']:
		print(dic['obad'])
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = input().split()
	even = 0
	odd = 0
	for i in range(n):
		x = int(arr[i])
		if i % 2 == 1 and x % 2 == 0:
			odd += 1
		if i % 2 == 0 and x % 2 == 1:
			even += 1
	if n == 1:
		print(-even)
	elif even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	e = 0
	c = 0
	for m in range(n):
		if a[m] % 2 != 0 and m % 2 == 0:
			e += 1
		elif a[m] % 2 == 0 and m % 2 != 0:
			c += 1
	if e == c:
		print(e)
	else:
		print('-1')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ec = 0
	f = 0
	for i in a:
		if i % 2 == 0:
			ec += 1
	if n % 2 == 0:
		if ec != n / 2:
			f = 0
		else:
			f = 1
	elif ec != int(n / 2) + 1:
		f = 0
	else:
		f = 1
	if f == 0:
		print('-1')
	else:
		s1 = 0
		for i in range(n):
			if i % 2 == 0:
				if a[i] % 2 != 0:
					s1 += 1
		print(s1)


for _ in range(int(input())):
	n = int(input())
	f = list(map(int, input().split()))
	ans = 0
	even = 0
	odd = 0
	for (k, v) in enumerate(f):
		if v % 2 == 0 and k % 2 == 1:
			even += 1
		elif v % 2 == 1 and 0 == k % 2:
			odd += 1
	if even - odd == 0:
		print(odd)
	else:
		print(-1)


import sys
import math
input = sys.stdin.readline
from collections import deque
from queue import LifoQueue

def binary_search(a, n):
	L = 0
	R = len(a) - 1
	while L <= R:
		mid = L + (R - L) // 2
		if a[mid] == n:
			return mid
		elif a[mid] < n:
			L = mid + 1
		else:
			R = mid - 1
	return -1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(ze, on) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			ze += 1
		elif i % 2 == 1 and a[i] % 2 != 1:
			on += 1
	if ze == on:
		print(ze)
	else:
		print(-1)


import math as Math
numberOfCases = int(input())
for _ in range(numberOfCases):
	length = int(input())
	arr = [int(x) for x in input().split(' ')]
	badPositions = 0
	numberOfEvenNumbers = 0
	numberOfOddNumbers = 0
	for i in range(length):
		if i % 2 != arr[i] % 2:
			badPositions += 1
		if arr[i] % 2 == 0:
			numberOfEvenNumbers += 1
		else:
			numberOfOddNumbers += 1
	if badPositions == 0:
		print(0)
		continue
	shouldBeEven = Math.ceil(length / 2)
	shouldBeOdd = length - shouldBeEven
	if numberOfEvenNumbers != shouldBeEven or numberOfOddNumbers != shouldBeOdd:
		print(-1)
	else:
		print(int(badPositions / 2))


T = int(input())
while T > 0:
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(0, n):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)
	T -= 1


import math
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	misplace = 0
	eve = 0
	odd = 0
	for i in range(len(a)):
		if i % 2 == 0:
			if a[i] % 2 == 0:
				eve += 1
			else:
				odd += 1
				misplace += 1
		elif a[i] % 2 == 1:
			odd += 1
		else:
			eve += 1
			misplace += 1
	if eve == math.ceil(len(a) / 2) and odd == math.floor(len(a) / 2):
		m = misplace // 2
	else:
		m = -1
	ans.append(m)
for i in ans:
	print(i)


t = int(input())
for wer in range(t):
	n = int(input())
	od = 0
	ed = 0
	li = list(map(int, input().split()))
	for i in range(n):
		if i % 2 != li[i] % 2:
			if i % 2 == 1:
				od += 1
			else:
				ed += 1
	if ed == od:
		print(ed)
	else:
		print('-1')


def read_arr():
	return [int(x) for x in input().split()]
n = int(input())
for i in range(n):
	n = int(input())
	a = read_arr()
	n_bad_odd = n_bad_even = 0
	for (i, x) in enumerate(a):
		if i % 2 == 0:
			if x % 2 != 0:
				n_bad_odd += 1
		elif x % 2 == 0:
			n_bad_even += 1
	if n_bad_odd == n_bad_even == 0:
		print(0)
	elif n_bad_odd == n_bad_even:
		print(n_bad_odd)
	else:
		print(-1)


def func(ls):
	even = 0
	odd = 0
	for (i, j) in enumerate(ls):
		if i % 2 == 0:
			if i % 2 == j % 2:
				continue
			else:
				even += 1
		elif i % 2 == j % 2:
			continue
		else:
			odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)
T = int(input())
for _ in range(T):
	ip = int(input())
	st = input().split(' ')
	st = list(map(int, st))
	func(st)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	bg = [0] * n
	for i in range(n):
		if a[i] % 2 == i % 2:
			bg[i] = 0
		else:
			bg[i] = 1
	mv = 0
	while 1 in bg:
		mved = False
		for i in range(n):
			for j in range(i + 1, n):
				if bg[i] and bg[j] and (a[i] % 2 != a[j] % 2):
					(a[i], a[j]) = (a[j], a[i])
					bg[i] = 0
					bg[j] = 0
					mved = True
					mv += 1
		if not mved:
			break
	if 1 in bg:
		print(-1)
	else:
		print(mv)


for case in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	(a1, a2) = [0, 0]
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				a1 += 1
		elif a[i] % 2 == 0:
			a2 += 1
	if a1 != a2:
		print(-1)
	else:
		print(a1)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even = 0
	odd = 0
	c = 0
	for j in range(n):
		if a[j] % 2 != j % 2:
			c += 1
		if a[j] % 2 == 0:
			even += 1
		else:
			odd += 1
	if n // 2 != odd:
		print(-1)
	else:
		print(c // 2)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	ocount = 0
	ecount = 0
	for i in range(n):
		if i % 2 != a[i] % 2 and i % 2 == 0:
			ecount += 1
		elif i % 2 != a[i] % 2 and i % 2 != 0:
			ocount += 1
	if ecount == ocount:
		print(ecount)
	else:
		print('-1')
	t -= 1


for _ in range(int(input())):
	num = int(input())
	lst = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(num):
		if i % 2 != lst[i] % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


r = int(input())
for i in range(r):
	l = int(input())
	num = input()
	list = [int(x) for x in num.split()]
	j = 0
	o = 0
	e = 0
	for i in range(l):
		if list[i] % 2 == 0:
			if i % 2 != 0:
				e += 1
			o += 1
		else:
			if i % 2 == 0:
				e += 1
			j += 1
	if l % 2 == 0 and o != j:
		print(-1)
	elif l % 2 != 0 and o != j + 1:
		print(-1)
	else:
		print(int(e / 2))


for _ in range(int(input())):
	_ = input()
	dict = list(map(int, input().split()))
	u = [0, 0]
	for (i, v) in enumerate(dict):
		u[i & 1] += i & 1 != v & 1
	print(u[i & 1] if u[0] == u[1] else -1)


t = int(input())
while t:
	n = int(input())
	nums = list(map(int, input().split()))
	if n == 1 and nums[0] % 2 != 0:
		print(-1)
	elif n == 1 and nums[0] % 2 == 0:
		print(0)
	else:
		(odd, eve) = (0, 0)
		for (i, v) in enumerate(nums):
			if i % 2 == 0:
				if v % 2 == 0:
					continue
				else:
					eve += 1
			elif v % 2 == 1:
				continue
			else:
				odd += 1
		if odd == eve:
			print(odd)
		else:
			print(-1)
	t -= 1


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	ans = []
	for _ in range(n):
		k = I()
		l = LI()
		a = b = 0
		for (i, x) in enumerate(l):
			if i % 2 != x % 2:
				if i % 2 == 0:
					a += 1
				else:
					b += 1
		if a != b:
			ans.append(-1)
		else:
			ans.append(a)
	for x in ans:
		print(x)
main()


for _ in range(int(input())):
	n = int(input())
	a = [int(item) for item in input().split()]
	c1 = 0
	c2 = 0
	for i in range(0, n):
		if i % 2 == 0 and a[i] % 2 != 0:
			c1 += 1
		elif i % 2 == 1 and a[i] % 2 != 1:
			c2 += 1
	if c1 != c2:
		print(-1)
	else:
		print(c1)


t = int(input())
for q in range(0, t):
	n = int(input())
	a = [int(i) for i in input().split()]
	count0 = 0
	count1 = 0
	for i in range(0, n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				count0 += 1
		elif a[i] % 2 == 0:
			count1 += 1
	if count0 == count1:
		print(count1)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	a = 0
	b = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 == 1:
			a += 1
		elif i % 2 == 1 and arr[i] % 2 == 0:
			b += 1
	if a == b:
		print(a)
	else:
		print(-1)


def process(x):
	num_even_odd = [0, 0]
	for i in range(len(x)):
		if x[i] % 2 != i % 2:
			num_even_odd[i % 2] += 1
	if num_even_odd[0] == num_even_odd[1]:
		return num_even_odd[0]
	else:
		return -1

def main():
	num_input = int(input())
	for _ in range(num_input):
		_ = int(input())
		arr = input()
		arr = arr.split()
		to_check = []
		for val in arr:
			to_check.append(int(val))
		result = process(to_check)
		print(result)
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l1 = []
	l2 = []
	for j in range(len(a)):
		if j % 2 == 0:
			if a[j] % 2 != 0:
				l1.append(a[j])
		elif a[j] % 2 == 0:
			l2.append(a[j])
	if len(l1) == len(l2):
		print(len(l1))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	(*a,) = map(int, input().split())
	a = [ai % 2 for ai in a]
	ii = [i for i in range(n) if a[i]]
	if len(ii) != n // 2:
		print(-1)
		continue
	ans = [(1 + ii[j]) % 2 for j in range(n // 2)]
	print(sum(ans))


def solution():
	n = int(input())
	a = list(map(int, input().split()))
	mo = 0
	me = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				me += 1
		elif a[i] % 2 == 0:
			mo += 1
	if mo != me:
		print(-1)
		return
	print(mo)
T = int(input())
while T:
	solution()
	T -= 1


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(n):
		if i % 2 == l[i] % 2:
			pass
		elif i % 2 == 0:
			e += 1
		else:
			o += 1
	else:
		if e == o:
			print(e)
		else:
			print('-1')


def solution(arr, n):
	(even, odd, wo, we) = (0, 0, 0, 0)
	for i in range(n):
		if i % 2 == 0:
			if arr[i] % 2 == 0:
				even += 1
			else:
				we += 1
		elif arr[i] % 2 == 0:
			wo += 1
		else:
			odd += 1
	if n % 2 == 0:
		if we + odd == wo + even:
			return we
		return -1
	else:
		if we + odd + 1 == wo + even:
			return wo
		return -1
tc = int(input())
for i in range(tc):
	n = int(input())
	arr = [int(x) for x in input().split()]
	print(solution(arr, n))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return list(map(int, input().split()))

def solve(a):
	bit_arr = [0] * len(a)
	_sum = 0
	change = 0
	for (i, num) in enumerate(a):
		if i % 2 != num % 2:
			change += 1
		if num % 2 != 0:
			_sum += 1
			bit_arr[i] = 1
	if _sum != len(a) // 2:
		return -1
	return change // 2
test = inp()
for t in range(test):
	n = inp()
	arr = inlt()
	print(solve(arr))


for i in range(int(input())):
	num = int(input())
	l = list(map(int, input().rstrip().split()))
	zero = []
	one = []
	k = [z for z in range(num)]
	flag = True
	for j in range(num):
		l[j] = l[j] % 2
		k[j] = k[j] % 2
		if l[j] != k[j]:
			if l[j] == 1:
				zero.append(j)
			else:
				one.append(j)
	if len(zero) == len(one):
		print(len(zero))
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	req = 0
	count = 0
	for i in range(n):
		if i % 2 == a[i] % 2:
			continue
		else:
			if i % 2 == 0:
				req -= 1
			else:
				req += 1
			count += 1
	if req == 0:
		print(count // 2)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	(*arr,) = map(int, input().split())
	odd_e = 0
	eve_e = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if arr[i] % 2 == 0:
				eve_e += 1
			else:
				odd_e += 1
	if eve_e == odd_e:
		print(eve_e)
	else:
		print(-1)


t = int(input())
count = 0
while count < t:
	count += 1
	n = int(input())
	l = list(map(int, input().split(' ')))
	weight = 0
	es = 0
	os = 0
	i = 0
	while i < n:
		if l[i] % 2 != i % 2:
			weight += 1
			if l[i] % 2 == 0:
				es += 1
			else:
				os += 1
		i += 1
	if weight % 2 == 1 or es - os >= 2 or os - es >= 2:
		print(-1)
	else:
		print(weight // 2)


t = int(input())
for _ in range(t):
	l = input()
	s = [int(i) for i in input().split(' ')]
	c = 0
	d = 0
	for (p, i) in enumerate(s):
		if p & 1 != i & 1:
			if p & 1:
				c += 1
			else:
				d += 1
	if c != d:
		print(-1)
	else:
		print(c)


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	oddbads = 0
	evenbads = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if a[i] % 2 == 1:
				oddbads += 1
			if a[i] % 2 == 0:
				evenbads += 1
	if oddbads == evenbads:
		print(oddbads)
	else:
		print('-1')


import sys, math
from collections import deque

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	even = 0
	for i in range(n):
		if a[i] % 2 == 0:
			even += 1
	if not (n % 2 == 0 and even == n // 2 or (n % 2 == 1 and even == n // 2 + 1)):
		print(-1)
		return
	correct = 0
	for i in range(n):
		if i % 2 == a[i] % 2:
			correct += 1
	print((n - correct) // 2)
	return
for _ in range(int(input())):
	solve()


my_value = []
for i in range(int(input())):
	num = int(input())
	lis = list(map(int, input().split()))
	count_old = 0
	count_even = 0
	for j in range(num):
		if j % 2 != 0 and lis[j] % 2 == 0:
			count_even += 1
		elif j % 2 == 0 and lis[j] % 2 != 0:
			count_old += 1
	if count_even == count_old:
		my_value.append(count_old)
	else:
		my_value.append(-1)
for i in my_value:
	print(i)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	co = 0
	ce = 0
	for i in range(len(l)):
		if i % 2 == l[i] % 2:
			c += 1
		elif i % 2 == 0:
			ce += 1
		else:
			co += 1
	if c == len(l):
		print(0)
	elif co == ce:
		print(co)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	if len(l) == 1:
		if l[0] % 2 == 1:
			c1 = c1 + 1
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 != 0:
			c1 = c1 + 1
		if i % 2 == 1 and l[i] % 2 != 1:
			c2 = c2 + 1
	if c1 > c2 or c2 > c1:
		print(-1)
	elif c1 == c2:
		print(c1)
	else:
		print(0)


n = int(input())
for _ in range(n):
	m = int(input())
	arr = input().split()
	wrong_odd = 0
	wrong_even = 0
	for i in range(m):
		if i % 2 == 0:
			if int(arr[i]) % 2 != 0:
				wrong_even += 1
		elif int(arr[i]) % 2 == 0:
			wrong_odd += 1
	if wrong_odd == wrong_even:
		print(wrong_even)
	else:
		print(-1)


n = int(input())

class solution:

	def __init__(self):
		self.__sol = []

	def add(self, a, n):
		d = {}
		d[1] = 0
		d[0] = 0
		for i in range(n):
			if a[i] % 2 != i % 2:
				d[a[i] % 2] += 1
		if d[1] != d[0]:
			self.__sol.append(-1)
		else:
			self.__sol.append(d[1])

	def afis(self):
		for i in self.__sol:
			print(i)
sol = solution()
while n:
	nr = int(input())
	a = [int(i) for i in input().split()]
	sol.add(a, nr)
	n -= 1
sol.afis()


t = int(input())
for i in range(t):
	n = int(input())
	s = [int(x) for x in input().split()]
	a = b = 0
	for j in range(n):
		if s[j] % 2 == 1 and j % 2 == 0:
			a += 1
		if s[j] % 2 == 0 and j % 2 == 1:
			b += 1
	if a == b:
		print(a)
	else:
		print(-1)


x = int(input())
for i in range(x):
	a = int(input())
	l = list(map(int, input().split()))
	c = 0
	sl = []
	st = []
	for i in range(a):
		if i % 2 != 0 and l[i] % 2 == 0:
			sl.append(l[i])
		if i % 2 == 0 and l[i] % 2 != 0:
			st.append(l[i])
	if len(sl) == len(st):
		print(len(sl))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	bodd = beven = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if i % 2:
				bodd += 1
			else:
				beven += 1
	print(bodd if bodd == beven else -1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	for i in range(n):
		if i % 2 == 0:
			l1.append(0)
		else:
			l1.append(1)
	l2 = []
	(o, e) = (0, 0)
	for i in range(n):
		if l[i] % 2 == 0:
			e += 1
		else:
			o += 1
		l2.append(l[i] % 2)
	if n % 2 == 0:
		if e != o:
			print(-1)
		else:
			cnt = 0
			for i in range(n):
				if l2[i] != l1[i]:
					cnt += 1
			print(cnt // 2)
	elif e != o + 1:
		print(-1)
	else:
		cnt = 0
		for i in range(n):
			if l2[i] != l1[i]:
				cnt += 1
		print(cnt // 2)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	odd = 0
	for i in range(n):
		if l[i] % 2 != i % 2:
			count = count + 1
		if l[i] % 2 != 0:
			odd = odd + 1
	if count % 2 == 0 and odd == n // 2:
		print(count // 2)
	else:
		print('-1')
	t = t - 1


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	e = []
	o = []
	for i in range(n):
		if i % 2 != l[i] % 2:
			if l[i] % 2 == 0:
				e.append(i)
			else:
				o.append(i)
	even = len(e)
	odd = len(o)
	if even == odd:
		print(even)
	else:
		print(-1)


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())

def main():
	n = itg()
	if n == 1:
		return 0 if itg() & 1 ^ 1 else -1
	arr = [a & 1 for a in mpint()]
	a1 = arr[::2]
	a2 = arr[1::2]
	idx = -1
	ans = 0
	for i in range(len(a1)):
		a = a1[i]
		if a:
			while True:
				idx += 1
				if idx == len(a2):
					return -1
				if a2[idx] == 0:
					ans += 1
					(a1[i], a2[idx]) = (a2[idx], a1[i])
					break
	return -1 if sum(a1) != 0 or sum(a2) != len(a2) else ans
for case in range(itg()):
	print(main())


from sys import stdin, stdout
import math
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, stdin.readline().split()))
	even = odd = wrong = 0
	for i in range(n):
		if a[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if i % 2 != a[i] % 2:
			wrong += 1
	possible = n % 2 == 0 and even == n / 2 and (odd == n / 2) or (n % 2 == 1 and even == int(n / 2) + 1 and (odd == int(n / 2)))
	if possible:
		if wrong % 2 == 0:
			print(int(wrong / 2))
		else:
			print(-1)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	o = 0
	e = 0
	for i in range(len(x)):
		if i % 2 != 0 and x[i] % 2 != 0 or (i % 2 == 0 and x[i] % 2 == 0):
			continue
		elif i % 2 != 0 and x[i] % 2 == 0:
			o += 1
		else:
			e += 1
	if o == e:
		print(o)
	else:
		print(-1)


tt = int(input())
for loop in range(tt):
	n = int(input())
	a = list(map(int, input().split()))
	o = 0
	e = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				e += 1
			else:
				o += 1
	if e != o:
		print(-1)
	else:
		print(e)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	p = []
	for i in l:
		p.append(i % 2)
	s = 0
	d = 0
	if p.count(0) != (n - 1) // 2 + 1:
		print(-1)
		continue
	for i in range(0, n, 2):
		if i == n - 1:
			d = d + 1
		elif p[i] == 1 and p[i + 1] == 0:
			s = s + 1
		elif p[i] == p[i + 1]:
			d = d + 1
	print(s + d // 2)


from sys import *
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	even = 0
	odd = 0
	count = 0
	result = True
	for i in a:
		if i % 2 == 0:
			even = even + 1
		else:
			odd = odd + 1
	if n % 2 == 0:
		if even != n // 2:
			print(-1)
			result = False
	elif even != n // 2 + 1:
		print(-1)
		result = False
	if result:
		for i in range(n):
			if i % 2 != a[i] % 2:
				count = count + 1
		print(int(count / 2))


t = int(input())
for i in range(t):
	n = int(input())
	evec = oddc = 0
	arr = [int(x) for x in input().split()]
	for j in range(n):
		lhs = j % 2
		rhs = arr[j] % 2
		if lhs != rhs:
			if lhs == 0 and rhs == 1:
				oddc += 1
			else:
				evec += 1
	count = min(oddc, evec)
	if abs(oddc - evec) >= 1:
		print(-1)
	else:
		print(count)


t = int(input())
for i in range(t):
	n = int(input())
	p = input().split()
	k = 0
	sumo = 0
	sume = 0
	while k < n:
		p[k] = int(p[k])
		if k % 2 == 0:
			if p[k] % 2 == 1:
				sume = sume + 1
		elif p[k] % 2 == 0:
			sumo = sumo + 1
		k = k + 1
	if sumo != sume:
		print('-1')
	else:
		print(sumo)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
	n = iinput()
	a = get_list()
	even = odd = 0
	e = o = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				e += 1
			else:
				o += 1
	if e == o:
		print(e)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	even = []
	odd = []
	for i in range(n):
		if a[i] % 2 == 0 and i % 2 == 1:
			odd.append(i)
		if a[i] % 2 == 1 and i % 2 == 0:
			even.append(i)
	if len(odd) == len(even):
		print(len(even))
	else:
		print(-1)


t = int(input())
for i in range(t):
	(n, s, k, m) = (int(input()), input().split(), 0, 0)
	for i in range(n):
		if int(s[i]) % 2 == 0:
			k = k + 1
			if i % 2 == 0:
				m = m + 1
	if k == (n + 1) // 2:
		print((n + 1) // 2 - m)
	else:
		print(-1)


def case(array):
	odds = 0
	evens = 0
	for number in array:
		if number % 2 == 1:
			odds += 1
		else:
			evens += 1
	if evens < odds or evens > odds + 1:
		return -1
	incorrects = 0
	for (index, number) in enumerate(array):
		if index % 2 != number % 2:
			incorrects += 1
	return int(incorrects / 2)
t = int(input())
answers = []
for test in range(t):
	n = int(input())
	array = input().split()
	array = [int(x) for x in array]
	ans = case(array)
	answers.append(ans)
for ans in answers:
	print(ans)


def swap_count(n, nums):
	(odd, even) = (0, 0)
	mismatch = 0
	(ideal_odd, ideal_even) = (n // 2, n - n // 2)
	for i in range(n):
		par1 = i % 2
		par2 = nums[i] % 2
		if par2 == 0:
			even += 1
		else:
			odd += 1
		if par1 != par2:
			mismatch += 1
	if odd != ideal_odd or even != ideal_even:
		return -1
	if mismatch == 0:
		return 0
	return mismatch // 2
T = int(input())
for t in range(T):
	n = int(input())
	numbers = list(map(int, input().split()))
	ans = swap_count(n, numbers)
	print(ans)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	wr_even = []
	wr_odd = []
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			wr_even.append(arr[i])
		elif i % 2 == 1 and arr[i] % 2 != 1:
			wr_odd.append(arr[i])
	if len(wr_even) == len(wr_odd):
		print(len(wr_even))
	else:
		print(-1)
t = int(input())
for _ in range(t):
	main()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = d = k = 0
	for i in l:
		if i % 2 == 0 and k % 2 != 0:
			c += 1
		if i % 2 != 0 and k % 2 == 0:
			d += 1
		k += 1
	if c == d:
		print(c)
	elif c < d or d < c:
		print('-1')
	else:
		print('0')


import sys
import math
from collections import defaultdict as dft
input = sys.stdin.readline

def ml():
	return list(map(int, input().split()))

def mp():
	return map(int, input().split())

def debug(name, val):
	print(name, ':', val)

def solve():
	n = int(input())
	arr = ml()
	lst = [0, 0]
	for i in range(n):
		rem = i % 2
		if arr[i] % 2 != rem:
			lst[rem] += 1
	if lst[0] != lst[1]:
		print(-1)
	else:
		print(lst[0])
t = int(input())
for _ in range(t):
	solve()


q = int(input())
for _ in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	zlep = 0
	zlen = 0
	for i in range(n):
		if i % 2 == 0:
			zlep += (i - l[i]) % 2
		else:
			zlen += (i - l[i]) % 2
	if zlen == zlep:
		print(zlen)
	else:
		print(-1)


n = int(input())
for _ in range(n):
	n1 = int(input())
	arr = list(map(int, input().split()))
	nodd = 0
	neven = 0
	owrong = 0
	ewrong = 0
	for i in range(n1):
		if arr[i] % 2 == 0:
			neven += 1
			if i % 2 == 1:
				ewrong += 1
		else:
			nodd += 1
			if i % 2 == 0:
				owrong += 1
	if n1 % 2 == 1 and nodd >= (n1 + 1) // 2:
		print(-1)
	elif n1 % 2 == 0 and neven > n1 // 2:
		print(-1)
	elif owrong != ewrong:
		print(-1)
	else:
		print(owrong)


import sys
input = sys.stdin.readline
for T in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 == 1:
			even += 1
		if i % 2 == 1 and arr[i] % 2 == 0:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	numbers = [int(x) for x in input().split()]
	odd_count = 0
	even_count = 0
	for i in range(n):
		if numbers[i] % 2:
			odd_count += 1
		else:
			even_count += 1
	condition_1 = abs(odd_count - even_count) <= 1
	condition_12 = even_count % 2 == 0 and even_count - 1 == odd_count
	condition_13 = even_count % 2 and odd_count + 1 == even_count
	condition_2 = n % 2 and (condition_12 or condition_13) and (even_count > 0) or (n % 2 == 0 and odd_count == even_count)
	if condition_1 and condition_2:
		count = 0
		for i in range(n - 1):
			for j in range(i + 1, n):
				if numbers[j] % 2 == i % 2 and numbers[i] % 2 != i % 2 and (numbers[j] % 2 != j % 2):
					(numbers[j], numbers[i]) = (numbers[i], numbers[j])
					count += 1
		print(count)
	else:
		print(-1)


from sys import stdin, stdout
import math

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	flag = 1
	(eve, odd) = (0, 0)
	for i in range(n):
		if l[i] % 2 != i % 2:
			if i % 2:
				odd += 1
			else:
				eve += 1
	if eve == odd:
		print(eve)
		return
	else:
		print(-1)
test = 1
test = int(input())
for __ in range(test):
	solve()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(lo, le) = ([], [])
	for i in range(n):
		if i % 2 != l[i] % 2:
			if i % 2 == 0:
				le.append(i)
			else:
				lo.append(i)
	if len(lo) == len(le):
		print(len(lo))
	else:
		print(-1)


T = int(input())
for _ in range(T):
	n = int(input())
	a = [int(i) % 2 for i in input().split()]
	ideal = [i % 2 for i in range(n)]
	if ideal.count(0) != a.count(0) or ideal.count(1) != a.count(1):
		print(-1)
	else:
		count = 0
		for i in range(n):
			if ideal[i] != a[i]:
				count += 1
		print(count // 2)


for loop in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 0:
			even += 1
		if i % 2 != 0 and a[i] % 2 != 0:
			odd += 1
	if n % 2 == 0 and even == odd:
		print(n // 2 - even)
		continue
	if n % 2 != 0 and even == odd + 1:
		print(n // 2 - odd)
		continue
	print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	e = odd = 0
	o = [int(i) for i in input().split(' ')]
	for (i, v) in enumerate(o):
		if i % 2 == 0:
			if v % 2 != 0:
				e += 1
		elif v % 2 == 0:
			odd += 1
	if e == odd:
		print(e)
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	for j in range(n):
		if a[j] % 2 == 1 and j % 2 == 0:
			count1 += 1
		elif a[j] % 2 == 0 and j % 2 == 1:
			count2 += 1
	if count1 == count2:
		print(int(count2))
	else:
		print('-1')


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	e = []
	o = []
	for i in range(len(b)):
		if i % 2 != b[i] % 2:
			if i % 2 == 0:
				e.append(b[i])
			else:
				o.append(b[i])
	k = abs(len(e) - len(o))
	if k == 0:
		print(len(e))
	else:
		print(-1)


import sys
tests = int(sys.stdin.readline().split()[0])
for test in range(tests):
	n = int(sys.stdin.readline().split()[0])
	a = [int(i) for i in sys.stdin.readline().split()]
	if n == 1:
		if a[0] % 2 == 0:
			print(0)
		else:
			print(-1)
		continue
	i = 0
	even_count = 0
	while i < n:
		if a[i] % 2 == 0:
			even_count += 1
		i += 1
	if n % 2 == 0:
		if even_count > n // 2 or n - even_count > n // 2:
			print(-1)
			continue
	elif even_count > n // 2 + 1 or n - even_count >= n // 2 + 1:
		print(-1)
		continue
	change_count = 0
	i = 0
	while i < n:
		if a[i] % 2 == 0 and i % 2 != 0 or (a[i] % 2 != 0 and i % 2 == 0):
			change_count += 1
		i += 1
	change_count = change_count // 2
	print(change_count)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	o = e = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 == 1:
				e += 1
		elif a[i] % 2 == 0:
			o += 1
	if e == o:
		print(e)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	for i in range(n):
		for j in range(i + 1, n):
			if (i % 2 == 0 and a[i] % 2 != 0) and (j % 2 != 0 and a[j] % 2 == 0) or ((i % 2 != 0 and a[i] % 2 == 0) and (j % 2 == 0 and a[j] % 2 != 0)):
				t = a[i]
				a[i] = a[j]
				a[j] = t
				c += 1
	f = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0 or (i % 2 != 0 and a[i] % 2 == 0):
			f = 1
			break
	if f == 1:
		print(-1)
	else:
		print(c)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = [int(x) for x in input().split()]
	ec = 0
	oc = 0
	for i in l:
		if i % 2 == 0:
			ec += 1
		else:
			oc += 1
	if n == 1:
		if oc == 1:
			print('-1')
		else:
			print('0')
	elif n % 2 != 0:
		if ec == n // 2 + 1 and oc == n // 2:
			k = 0
			for i in range(0, n, 2):
				if l[i] % 2 != 0:
					k += 1
			print(k)
		else:
			print('-1')
	elif ec == n // 2 and oc == n // 2:
		k = 0
		for i in range(0, n, 2):
			if l[i] % 2 != 0:
				k += 1
		print(k)
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(n):
		if i & 1 == 0 and a[i] & 1 != 0:
			e += 1
		if i & 1 != 0 and a[i] & 1 == 0:
			o += 1
	if e == o:
		print(e)
	else:
		print(-1)


t = int(input())
for v in range(t):
	n = int(input())
	li = list(map(int, input().split(' ')))
	eo = 0
	oe = 0
	for i in range(n):
		if i % 2 == 0:
			if li[i] % 2 != 0:
				eo += 1
		elif li[i] % 2 != 1:
			oe += 1
	if oe != eo:
		print(-1)
	else:
		print(eo)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	neg = 0
	add = 0
	for i in range(n):
		if i & 1 != 0 and arr[i] & 1 == 0:
			add += 1
		elif i & 1 == 0 and arr[i] & 1 != 0:
			neg += 1
	if add == neg:
		stdout.write(f'{add}\n')
	else:
		stdout.write('-1\n')


t = int(input())
for i in range(t):
	n = int(input())
	seq = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	for i in range(n):
		if seq[i] % 2 == 0 and i % 2 != 0:
			c1 += 1
		if seq[i] % 2 != 0 and i % 2 == 0:
			c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	wrong_odds = sum((arr[i] % 2 == 0 for i in range(1, n, 2)))
	wrong_evens = sum((arr[i] % 2 == 1 for i in range(0, n, 2)))
	if wrong_odds != wrong_evens:
		print(-1)
	else:
		print(wrong_odds)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	N = int(input())
	A = alele()
	swap = 0
	f = 0
	for i in range(N):
		if A[i] % 2 != i % 2:
			g = 0
			for j in range(i + 1, N):
				if A[j] % 2 == i % 2 and A[j] % 2 != j % 2:
					g = 1
					(A[i], A[j]) = (A[j], A[i])
					swap += 1
					break
			if g == 0:
				f = 1
				break
		if f == 1:
			break
	if f == 0:
		print(swap)
	else:
		print(-1)


test_cases = int(input())
for _ in range(test_cases):
	input()
	arr = list(map(int, input().split()))
	m = [0, 0]
	for i in range(len(arr)):
		if i % 2 != arr[i] % 2:
			m[i % 2] += 1
	if m[0] == m[1]:
		print(m[1])
	else:
		print(-1)


test = int(input())
test_arr = []
for _ in range(test):
	n = int(input())
	arr = list(map(int, input().split()))
	wrong = 0
	right = 0
	even = 0
	odd = 0
	for (i, a) in enumerate(arr):
		cond1 = a % 2
		cond2 = i % 2
		if cond1 and cond2 or (not cond1 and (not cond2)):
			right += 1
		else:
			wrong += 1
		if cond1:
			even += 1
		else:
			odd += 1
	if even == n // 2:
		ans = wrong // 2
	else:
		ans = -1
	test_arr.append(ans)
for t in test_arr:
	print(t)


t = int(input(''))
for i in range(t):
	count = 0
	l = int(input(''))
	a = [int(x) for x in input('').split()]
	e = []
	o = []
	for i in range(l):
		if i % 2 == 1 and a[i] % 2 == 0:
			e.append(i)
		elif i % 2 == 0 and a[i] % 2 == 1:
			o.append(i)
	if len(e) == len(o):
		print(len(e))
	else:
		print(-1)


n1 = int(input())
for j in range(n1):
	n = int(input())
	sin = input()
	sin = sin.split()
	c1 = 0
	c2 = 0
	for i in range(n):
		if i % 2 == 0 and int(sin[i]) % 2 != 0:
			c1 = c1 + 1
		elif i % 2 != 0 and int(sin[i]) % 2 == 0:
			c2 = c2 + 1
	if c1 == c2:
		print(c1)
	else:
		print('-1')


for _ in range(int(input())):
	k = int(input())
	i = list(map(int, input().split()))
	j = []
	for l in range(k):
		if l % 2 == 0:
			if i[l] % 2 == 0:
				j.append(0)
			else:
				j.append('e')
		elif i[l] % 2 != 0:
			j.append(0)
		else:
			j.append('o')
	count1 = j.count('e')
	count2 = j.count('o')
	if count1 != count2:
		print(-1)
	else:
		print(count1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even = odd = 0
	for j in range(0, n):
		if j % 2 != a[j] % 2:
			if j % 2 == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


for _ in range(int(input())):
	c = 0
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] % 2 == 1:
			c += 1
	if c > n // 2 or c < n // 2:
		print('-1')
	else:
		c = 0
		for i in range(n):
			if i % 2 == 0:
				if a[i] % 2 == 1:
					c += 1
		print(c)


for _ in range(int(input())):
	b = int(input())
	a = list(map(int, input().split()))
	even = len([i for i in a if i % 2 == 0])
	odd = b - even
	if even < b / 2 or even > (b + 1) / 2:
		print(-1)
	else:
		c = 0
		for i in range(len(a)):
			if i % 2 != a[i] % 2:
				for j in range(i + 1, len(a), 2):
					if j % 2 != a[j] % 2:
						(a[i], a[j]) = (a[j], a[i])
						c += 1
						break
		print(c)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	index_parity = []
	for i in range(n):
		if i % 2 == 0:
			index_parity.append(0)
		else:
			index_parity.append(1)
	odd = []
	even = []
	for i in range(n):
		if i % 2 == 0:
			if arr[i] % 2 != index_parity[i]:
				odd.append(arr[i] % 2)
		elif arr[i] % 2 != index_parity[i]:
			even.append(arr[i] % 2)
	if len(odd) == len(even):
		print(len(odd))
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(n):
		if a[i] % 2 == 0:
			e += 1
		else:
			o += 1
	if o == n or (n > 1 and n == e) or (n % 2 == 0 and e != o) or (n % 2 == 1 and e - o != 1):
		print(-1)
	else:
		oi = 1
		ei = 0
		c = 0
		while True:
			while ei < n and a[ei] % 2 == 0:
				ei += 2
			while oi < n and a[oi] % 2 == 1:
				oi += 2
			if ei < n and oi < n:
				c += 1
				(a[ei], a[oi]) = (a[oi], a[ei])
			else:
				break
		print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(ans, ok, even, odd) = (0, 1, 0, 0)
	for x in range(n):
		if ok == 1:
			ok = x % 2 == a[x] % 2
		ans += x % 2 == a[x] % 2
		even += a[x] % 2 == 0
		odd += a[x] % 2
	if ok:
		print(0)
	else:
		print([-1, (n - ans) // 2][even == (n + 1) // 2 and odd == n - even])


for i in range(int(input())):
	x = input()
	line = input()
	a = line.split(' ')
	b = []
	for j in range(len(a)):
		if int(a[j]) % 2 == j % 2:
			b.append(0)
		else:
			b.append(1)
		a[j] = int(a[j]) % 2
	if a.count(0) != a.count(1) + 1 and a.count(0) != a.count(1):
		print('-1')
	else:
		print(b.count(1) // 2)


def solve(array, length):
	(a, b, output) = (0, 0, 0)
	for e in range(length):
		if array[e] % 2 != e % 2:
			if e % 2 == 0:
				a += 1
			else:
				b += 1
	if a != b:
		output -= 1
	else:
		output += a
	return output
t = int(input())
for i in range(t):
	n = int(input())
	a1 = list(map(int, input().split()))
	print(solve(a1, n))


testcases = int(input())
for i in range(testcases):
	len_array = int(input())
	array = list(map(int, input().split()))
	bad_even = 0
	bad_odd = 0
	for iter1 in range(len_array):
		if iter1 % 2 == 1:
			if array[iter1] % 2 != 1:
				bad_odd += 1
		elif array[iter1] % 2 != 0:
			bad_even += 1
	if bad_even == bad_odd:
		print(bad_even)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	e = []
	o = []
	for i in range(n):
		if i % 2 != a[i] % 2 and i % 2 == 0:
			o.append(i)
		elif i % 2 != a[i] % 2 and i % 2 != 0:
			e.append(i)
	if len(o) != len(e):
		print(-1)
	else:
		print(len(o))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	ans = 0
	for j in range(n):
		if a[j] % 2 == 0:
			cnt += 1
		if j % 2 != a[j] % 2:
			ans += 1
	if cnt != -(-n // 2):
		print(-1)
	else:
		print(ans // 2)


from sys import stdin, stdout
from collections import deque, defaultdict
from math import ceil, floor, inf, sqrt, factorial, gcd, log2
from copy import deepcopy
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
for _ in range(ii1()):
	n = ii1()
	arr = iia()
	(count, count2) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			if i % 2 != arr[i] % 2:
				count += 1
		elif i % 2 != arr[i] % 2:
			count2 += 1
	if count != count2:
		print(-1)
	else:
		print(count)


for tt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(E, O) = (0, 0)
	for i in range(n):
		if i & 1 and a[i] & 1 == 0:
			O += 1
		elif i & 1 == 0 and a[i] & 1:
			E += 1
	if E == O:
		print(E)
	else:
		print(-1)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = int(input())
for t in range(test_count):
	n = inp()
	a = inlt()
	mismatched = 0
	even = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 0 or (i % 2 == 1 and a[i] % 2 == 1):
			pass
		else:
			mismatched += 1
		if a[i] % 2 == 0:
			even += 1
	odd = n - even
	if n % 2 == 0 and 2 * even != n or (n % 2 == 1 and 2 * even != n + 1):
		print(-1)
	elif mismatched % 2 == 1:
		print(-1)
	else:
		print(mismatched // 2)


l = int(input())
for i in range(l):
	k = int(input())
	s = list(map(int, input().split()))
	z = 0
	o = 0
	for i in range(k):
		if i % 2 == 0 and s[i] % 2 != 0:
			z += 1
		elif i % 2 == 1 and s[i] % 2 != 1:
			o += 1
	if z == o:
		print(z)
	else:
		print(-1)


from math import inf as inf
from collections import *
import sys
from itertools import permutations
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	(wo, we) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and a[i] % 2:
			we += 1
		elif i % 2 and a[i] % 2 == 0:
			wo += 1
	if wo != we:
		print(-1)
		continue
	print(wo)


import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	even = odd = 0
	for i in range(n):
		if l[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	prb = 0
	if even == math.ceil(n / 2):
		for i in range(n):
			if i % 2 == 0 and l[i] % 2 == 1:
				prb += 1
			elif i % 2 == 1 and l[i] % 2 == 0:
				prb += 1
		print(prb // 2)
	else:
		print('-1')


import math
t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	cnt1 = 0
	cnt2 = 0
	for i in range(n):
		if l[i] % 2 == 0 and i % 2 == 0:
			cnt1 += 1
		elif l[i] % 2 != 0 and i % 2 != 0:
			cnt2 += 1
	if n % 2 == 0 and cnt1 == cnt2:
		print(int(n / 2) - cnt1)
	elif n % 2 != 0 and cnt2 == cnt1 - 1:
		print(int(n / 2) + 1 - cnt1)
	else:
		print('-1')
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	li = list(map(int, input().split()))
	for i in range(n):
		li[i] = li[i] % 2
	even = li.count(0)
	odd = li.count(1)
	if even == odd or even - 1 == odd:
		for i in range(0, n, 2):
			if li[i] == 1:
				count += 1
		print(count)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	for i in range(n):
		if abs(a[i] - i) % 2 != 0:
			l.append(a[i])
	ce = 0
	co = 0
	for i in l:
		if i % 2 == 0:
			ce += 1
		else:
			co += 1
	if ce != co:
		print(-1)
	else:
		print(co)


from sys import stdin, stdout, setrecursionlimit
from gc import disable
gets = input
puts = print
input = stdin.readline
print = stdout.write

def main() -> int:
	disable()
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		good = bad = 0
		odd = 0
		for i in range(n):
			if a[i] & 1 == i & 1:
				good += 1
			else:
				bad += 1
			odd += a[i] & 1
		even = n - odd
		if not bad:
			print('0\n')
		elif odd == n // 2 and even == n - n // 2:
			print('%d\n' % (bad >> 1))
		else:
			print('-1\n')
	return 0
main()


def main():
	for _ in range(int(input())):
		n = int(input())
		ar = list(map(int, input().split()))
		neven = nodd = 0
		for i in ar:
			if i % 2 == 0:
				neven += 1
			else:
				nodd += 1
		if n % 2 == 0 and neven != nodd:
			print(-1)
		elif n % 2 == 1 and neven - nodd != 1:
			print(-1)
		else:
			ar2 = [i % 2 - ar[i] % 2 for i in range(n)]
			ans = 0
			for i in ar2:
				if i != 0:
					ans += 1
			print(int(ans / 2))
main()


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split(' ')))
	if len(s) > 1:
		e = 0
		o = 0
		for i in range(n):
			if i % 2 != s[i] % 2:
				if i % 2 == 0:
					e += 1
				else:
					o += 1
		if e == o:
			print(e)
		else:
			print(-1)
	elif s[0] % 2 == 0:
		print(0)
	else:
		print(-1)


import sys

def main():
	t = int(next(sys.stdin))
	for _ in range(t):
		next(sys.stdin)
		ln = next(sys.stdin)
		xs = list(map(int, ln.split()))
		print(solve(xs))

def solve(xs):
	ans = 0
	odd = even = 0
	for (i, x) in enumerate(xs):
		if i % 2 != x % 2:
			odd += x % 2 == 1
			even += x % 2 == 0
	if odd != even:
		return -1
	return odd
main()


n = int(input())
lng = [0 for i in range(n)]
lists = [0 for i in range(n)]
for i in range(n):
	len = input()
	del len
	lists[i] = [int(x) for x in input().split()]

def check(list):
	even = []
	odd = []
	for i in range(len(list)):
		if list[i] % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	if len(even) - len(odd) > 1 or len(odd) > len(even):
		return -1
	else:
		return max(cnte(even), cnto(odd))

def cnte(list):
	num = 0
	for i in range(len(list)):
		if list[i] % 2 != 0:
			num += 1
	return num

def cnto(list):
	num = 0
	for i in range(len(list)):
		if list[i] % 2 == 0:
			num += 1
	return num
for i in range(n):
	print(check(lists[i]))


t = int(input())
while t:
	n = int(input())
	a = [int(i) for i in input().split()]
	eve = 0
	odd = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if i % 2 == 1:
				odd += 1
			else:
				eve += 1
	if eve != odd:
		print(-1)
	else:
		print(eve)
	t -= 1


def noOfSwaps(arr, n):
	count = 0
	rem_i = []
	new_i = []
	(res, new) = (0, 0)
	for i in range(n):
		rem_i.append(i % 2)
		new_i.append(arr[i] % 2)
	for i in range(n):
		res = res ^ i % 2
		new = new ^ arr[i] % 2
	if new > res:
		return -1
	else:
		for i in range(n):
			if rem_i[i] != new_i[i]:
				count += 1
		return count // 2

def returnsCount(arr, n):
	(even, odd) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			even += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			odd += 1
	if even == odd:
		return even
	else:
		return -1
test = int(input())
for _ in range(test):
	n = int(input())
	arr = list(map(int, input().split()))
	print(returnsCount(arr, n))


def main(ar):
	(evens, mismatches) = (0, 0)
	for i in range(len(ar)):
		num = ar[i]
		if num % 2 == 0:
			evens += 1
		if i % 2 != num % 2:
			mismatches += 1
	odds = len(ar) - evens
	if len(ar) % 2 != evens - odds:
		return -1
	else:
		return mismatches // 2
n = int(input())
results = []
for i in range(n):
	l = int(input())
	case = list(map(int, input().replace(',', ' ').split()))
	results.append(main(case))
print(*results, sep='\n')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	count = 0
	o = 0
	e = 0
	for i in range(n):
		if a[i] % 2 == i % 2:
			continue
		if i % 2 == 1:
			o += 1
		else:
			e += 1
	if o == e:
		print(o)
	else:
		print(-1)


from sys import stdin

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	n = iinput()
	a = linput()
	(ev, od) = (0, 0)
	for i in range(n):
		if a[i] & 1 != i & 1:
			if i & 1:
				od += 1
			else:
				ev += 1
	if ev != od:
		print(-1)
	else:
		print(ev)


t = int(input())
for i in range(t):
	n = int(input())
	s = [int(x) for x in input().split()]
	k = [a for a in s if a % 2 == 0]
	ce = len(k)
	co = n - ce
	if n % 2 == 0 and ce != co:
		print('-1')
	elif n % 2 == 0:
		ccc = 0
		for j in range(n):
			if s[j] % 2 != j % 2:
				ccc = ccc + 1
		print(int(ccc / 2))
	elif ce - co != 1:
		print('-1')
	else:
		ccc = 0
		for j in range(n):
			if s[j] % 2 != j % 2:
				ccc = ccc + 1
		print(int(ccc / 2))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	odd = n // 2
	even = n - odd
	for i in a:
		if i % 2:
			odd -= 1
		else:
			even -= 1
	if not odd == even == 0:
		print(-1)
		continue
	ans = 0
	for i in range(n):
		if a[i] % 2 == i % 2:
			continue
		else:
			ans += 1
	print(ans // 2)


x = int(input())
for xxx in range(x):
	input()
	li = list(map(int, input().split()))
	if len(li) == 1 and li[0] % 2 == 1:
		print(-1)
		continue
	(e, o) = ([], [])
	for i in range(len(li)):
		if li[i] % 2 == 0:
			e.append(i)
		else:
			o.append(i)
	if len(li) % 2 == 0:
		if len(e) == len(o):
			y = 0
			for i in e:
				if i % 2:
					y += 1
			for i in o:
				if i % 2 == 0:
					y += 1
			print(y // 2)
		else:
			print(-1)
	elif len(e) == len(o) + 1:
		q = 0
		for i in e:
			if i % 2:
				q += 1
		for i in o:
			if i % 2 == 0:
				q += 1
		print(q // 2)
	else:
		print(-1)


for _ in range(int(input())):
	x = int(input())
	myList = list(map(int, input().split()))
	sum = even = odd = 0
	for i in range(x):
		if myList[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if myList[i] % 2 != i % 2:
			sum += 1
	print(sum // 2 if sum % 2 == 0 and (even + 1 == odd or odd + 1 == even or odd == even) else -1)


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	a2 = []
	a1 = []
	for i in range(0, n, 1):
		if i % 2 == 0:
			a1.append(0)
		else:
			a1.append(1)
		if a[i] % 2 == 0:
			a2.append(0)
		else:
			a2.append(1)
	if a1 == a2:
		print(0)
	elif sum(a1) != sum(a2):
		print(-1)
	else:
		c = 0
		for i in range(0, n - 1, 1):
			if a1[i] != a2[i]:
				for j in range(i + 1, n, 1):
					if a1[j] != a2[j] and a2[j] == a1[i]:
						c += 1
						temp = a2[i]
						a2[i] = a2[j]
						a2[j] = temp
						break
		print(c)


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().strip().split(' ')))
	odd_count = 0
	even_count = 0
	for j in range(n):
		if j % 2 == 0:
			if lst[j] % 2 != 0:
				even_count += 1
		if j % 2 != 0:
			if lst[j] % 2 == 0:
				odd_count += 1
	if odd_count == even_count:
		print(odd_count)
	else:
		print('-1')


import sys
from os import path
if path.exists('C:/Users/prana/Desktop/sublime/input.txt'):
	sys.stdin = open('C:/Users/prana/Desktop/sublime/input.txt', 'r')
	sys.stdout = open('C:/Users/prana/Desktop/sublime/output.txt', 'w')

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	od = 0
	odd = 0
	ev = 0
	even = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 == 0:
				ev += 1
				even += 1
			else:
				odd += 1
		elif a[i] % 2 != 0:
			od += 1
			odd += 1
		else:
			even += 1
	if n % 2 == 0 and odd == even:
		print(min(n // 2 - ev, n // 2 - od))
	elif n % 2 != 0 and even - odd == 1:
		print(min(n // 2 + 1 - ev, n // 2 - od))
	else:
		print(-1)
T = 1
T = int(input())
for _ in range(1, T + 1):
	print('Case #', _, file=sys.stderr)
	solve()


def even_arr(arr):
	misfit = []
	for (i, num) in enumerate(arr):
		if num % 2 != i % 2:
			misfit.append(num)
	if not misfit:
		return 0
	e = 0
	o = 0
	for i in misfit:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
	if e == o:
		return e
	return -1
t = int(input())
for i in range(t):
	n = int(input())
	x = list(map(int, input().rstrip().split()))
	print(even_arr(x))


def solve(arr, oddcount, evencount):
	evenateven = 0
	for i in range(0, len(arr), 2):
		if arr[i] % 2 == 0:
			evenateven += 1
	return evencount - evenateven

def good(arr):
	n = len(arr)
	oddcount = 0
	for i in arr:
		if i % 2 == 1:
			oddcount += 1
	move = -1
	evencount = n - oddcount
	if n % 2 == 0:
		if oddcount == evencount:
			move = solve(arr, oddcount, evencount)
	if n % 2 != 0:
		if evencount == oddcount + 1:
			move = solve(arr, oddcount, evencount)
	return move
for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	print(good(arr))


for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	d = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 1:
				c += 1
			else:
				d += 1
	if c == d:
		print(c)
	else:
		print(-1)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	cntt = 0
	for i in range(n):
		if i % 2 != 0 and a[i] % 2 == 0:
			cnt += 1
		elif i % 2 == 0 and a[i] % 2 != 0:
			cntt += 1
	if cnt == cntt and (cnt + cntt) % 2 == 0:
		print(int((cnt + cntt) / 2))
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	odd = 0
	even = 0
	false_odd = 0
	false_even = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if arr[i] % 2 == 0 and i % 2 != 0:
			false_even += 1
		if arr[i] % 2 == 1 and i % 2 != 1:
			false_odd += 1
	if odd != n // 2:
		ans = -1
	elif false_even == false_odd:
		ans = false_odd
	else:
		ans = -1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ec = 0
	oc = 0
	f = 0
	for i in range(n):
		if i & 1 == 0 and l[i] & 1 == 1:
			ec += 1
			f = 1
		elif i & 1 == 1 and l[i] & 1 == 0:
			oc += 1
			f = 1
	if f == 0:
		print(0)
	elif ec == oc:
		print(ec)
	else:
		print(-1)


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	x = [0] * 2
	for i in range(n):
		if a[i] & 1 != i & 1:
			x[i & 1] += 1
	print(-1 if x[0] != x[1] else x[0])


def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	odd = even = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			if arr[i] % 2 != 0:
				odd += 1
		if i % 2 == 1:
			if arr[i] % 2 != 1:
				even += 1
	if odd != even:
		print(-1)
	else:
		print(odd)

def main():
	n = int(input())
	while n > 0:
		solve()
		n -= 1
main()


def swap():
	cnt = 0
	q = 0
	r = 0
	l = 0
	n = int(input())
	A = list(map(int, input().split()))
	for i in range(n):
		if A[i] % 2 == 0:
			r += 1
		if A[i] % 2 != 0:
			l += 1
	if r - l == 0 or r - l == 1:
		for i in range(n):
			if A[i] % 2 != i % 2:
				q += 1
		q = q // 2
		return q
	else:
		return -1
m = int(input())
for j in range(m):
	print(swap())


n = int(input())
for i in range(n):
	m = int(input())
	a = [int(i) for i in input().split()]
	even_wrong = 0
	odd_wrong = 0
	for j in range(m):
		if j % 2 != 0 and a[j] % 2 == 0:
			even_wrong += 1
		elif j % 2 == 0 and a[j] % 2 != 0:
			odd_wrong += 1
	if even_wrong == odd_wrong:
		print(even_wrong)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = l[0::2]
	b = l[1::2]
	a_count = 0
	b_count = 0
	for i in a:
		if i % 2 != 0:
			a_count += 1
	for i in b:
		if i % 2 == 0:
			b_count += 1
	if a_count == 0 and b_count == 0:
		print(0)
	elif a_count == b_count:
		print(a_count)
	else:
		print(-1)


for i1 in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	odd = 0
	even = 0
	for i in range(len(l)):
		if l[i] % 2 == 0 and i % 2 != 0:
			even += 1
		elif l[i] % 2 != 0 and i % 2 == 0:
			odd += 1
	if odd != even:
		print(-1)
	else:
		print(even)


T = int(input())
while T:
	T = T - 1
	n = input()
	arr = list(map(int, input().strip().split()))
	(even, odd) = (0, 0)
	for i in range(len(arr)):
		if i % 2 != arr[i] % 2:
			if i % 2:
				odd = odd + 1
			else:
				even = even + 1
	if odd == even:
		print(odd)
	else:
		print(-1)


t = int(input())
for i in range(0, t):
	l = int(input())
	ar = list(map(int, input().split()))
	if l == 1:
		if ar[0] % 2 == 0:
			print(0)
		else:
			print(-1)
	else:
		o = 0
		for i in ar:
			if i % 2 == 1:
				o = o + 1
		if l // 2 == o:
			c = 0
			for i in range(len(ar)):
				if i % 2 != ar[i] % 2:
					c += 1
			print(c // 2)
		else:
			print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	x = 0
	y = 0
	q = 0
	k = 0
	k1 = 0
	for j in range(n):
		x += j
		y += a[j]
		if j % 2 != a[j] % 2:
			q += 1
		if a[j] % 2 == 0:
			k += 1
		else:
			k1 += 1
	if x % 2 != y % 2 and q % 2 != 0:
		print(-1)
	elif k1 != n // 2:
		print(-1)
	elif k != (n + 1) // 2:
		print(-1)
	else:
		print(q // 2)


for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count_ch = 0
	count = 0
	for i in range(n):
		if a[i] % 2 == 0:
			count_ch += 1
		if a[i] % 2 != i % 2:
			count += 1
	if count_ch == (n + 1) // 2:
		print((count + 1) // 2)
	else:
		print(-1)


t = int(input())
rec = [0] * t
for i in range(t):
	n = int(input())
	c = [0] * 2
	s = input().split(' ')
	for j in range(n):
		test = int(s[j])
		if j % 2 != test % 2:
			c[j % 2] += 1
	if c[0] == c[1]:
		rec[i] = c[0]
	else:
		rec[i] = -1
for i in range(t):
	print(rec[i])


numCases = int(input())
for case in range(numCases):
	length = int(input())
	array = input().split(' ')
	num_odd_needSwapping = 0
	num_even_needSwapping = 0
	for i in range(length):
		i_mod = i % 2
		parity = i_mod == int(array[i]) % 2
		if not parity and i % 2 == 0:
			num_even_needSwapping += 1
		elif not parity and i % 2 == 1:
			num_odd_needSwapping += 1
	if num_even_needSwapping != num_odd_needSwapping:
		print(-1)
	else:
		print(num_even_needSwapping)


t = int(input())
for k in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	flag = True
	ev = 0
	od = 0
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 == 0 or (i % 2 != 0 and l[i] % 2 != 0):
			continue
		else:
			flag = False
			if i % 2 == 0:
				ev += 1
			else:
				od += 1
	if flag == False:
		if od == ev:
			print(od)
		else:
			print(-1)
	elif flag == True:
		print(0)


t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	chet = 0
	nechet = 0
	for i in range(n):
		if a[i] % 2 == 0:
			chet += 1
		else:
			nechet += 1
	if chet != nechet and chet != nechet + 1:
		print('-1')
		continue
	chetn = 0
	nechetn = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 0:
				chetn += 1
			else:
				nechetn += 1
	if nechetn != chetn:
		print('-1')
		continue
	print(chetn)


t = int(input())
for T in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	even = 0
	oddW = 0
	evenW = 0
	for i in range(n):
		if a[i] % 2 == 0:
			even += 1
			if i % 2 != 0:
				evenW += 1
		else:
			odd += 1
			if i % 2 == 0:
				oddW += 1
	if evenW != oddW:
		print(-1)
	else:
		print(oddW)


t = int(input())
for item in range(t):
	a = int(input())
	lst = [int(i) for i in input().split()]
	m = 0
	n = 0
	for j in range(a):
		if j % 2 == 0 and lst[j] % 2 != 0:
			m += 1
		elif j % 2 != 0 and lst[j] % 2 == 0:
			n += 1
	if m == n:
		print(m)
	elif m != n:
		print(-1)


n = int(input())
for i in range(n):
	x = int(input())
	y = list(map(int, input().split()))
	c = 0
	z1 = 0
	z2 = 0
	for j in range(x):
		if y[j] % 2 == 1 and c == 0:
			z1 = z1 + 1
		elif y[j] % 2 == 0 and c == 1:
			z2 = z2 + 1
		if c == 0:
			c = 1
		else:
			c = 0
	if z1 == z2:
		print(z1)
	else:
		print(-1)


T = int(input())
while T > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	misplace_even = 0
	misplace_odd = 0
	for i in range(n):
		if i % 2 == 0:
			if arr[i] % 2 == 1:
				misplace_odd += 1
		elif arr[i] % 2 == 0:
			misplace_even += 1
	if misplace_even != misplace_odd:
		print(-1)
	else:
		print(misplace_odd)
	T -= 1


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 0
	(even, odd) = (0, 0)
	while i < n:
		val = arr[i] % 2
		if val == i % 2:
			i += 1
		else:
			if val:
				odd += 1
			else:
				even += 1
			i += 1
	if even == odd:
		print(even)
	else:
		print(-1)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
t = iinput()
for _ in range(t):
	n = iinput()
	A = rlinput()
	incorrect_even = 0
	incorrect_odd = 0
	for i in range(n):
		if i % 2 == 0:
			if A[i] % 2 != 0:
				incorrect_even += 1
		if i % 2 != 0:
			if A[i] % 2 == 0:
				incorrect_odd += 1
	if incorrect_even == incorrect_odd:
		print(incorrect_even)
	else:
		print(-1)


t = int(input())
for z in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = []
	ai = []
	for i in range(n):
		f = l[i] % 2
		g = i % 2
		a.append(f)
		ai.append(g)
	r = []
	for i in range(n):
		if a[i] == ai[i]:
			a[i] = 2
			ai[i] = 2
		else:
			pass
	if a.count(1) == ai.count(1) and a.count(0) == ai.count(0):
		print(a.count(1))
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	d = 0
	for x in range(len(l)):
		if x % 2 == 0 and l[x] % 2 != 0:
			c += 1
		elif x % 2 == 1 and l[x] % 2 != 1:
			d += 1
	if c == d:
		print(c)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	inp = [int(k) for k in input().split()]
	(numones, numOnes) = (0, 0)
	posDiff = 0
	for i in range(len(inp)):
		if inp[i] % 2 == 1:
			numones = numones + 1
		if i % 2 == 1:
			numOnes = numOnes + 1
		if inp[i] % 2 == 0 and i % 2 == 1:
			posDiff = posDiff + 1
		if inp[i] % 2 == 1 and i % 2 == 0:
			posDiff = posDiff + 1
	if numones != numOnes:
		print(-1)
		continue
	print(posDiff // 2)


import math
a = int(input())
c = []
for i in range(a):
	d = input()
	b = input().split()
	for j in range(int(d)):
		b[j] = int(b[j])
	c.append(b)
for i in range(a):
	odd = 0
	even = 0
	matching_odd = 0
	matching_even = 0
	for j in range(len(c[i])):
		if c[i][j] % 2 == 0:
			even += 1
			if j % 2 == 0:
				matching_even += 1
		else:
			odd += 1
			if j % 2 == 1:
				matching_odd += 1
	reqeven = math.floor(len(c[i]) / 2.0 + 0.5)
	reqodd = math.ceil(len(c[i]) / 2.0 - 0.5)
	if odd != reqodd or even != reqeven:
		print(-1)
	else:
		print(int((len(c[i]) - matching_odd - matching_even) / 2))


t = int(input())
numbers = []
for i in range(t):
	input()
	numbers.append(list(map(int, input().split())))
for numberList in numbers:
	count = int(0)
	index = int(0)
	odds = int(0)
	for number in numberList:
		if number % 2 == 0:
			odds += 1
		else:
			odds -= 1
		if index % 2 == 0 and number % 2 != 0:
			count += 1
		elif index % 2 != 0 and number % 2 == 0:
			count += 1
		index += 1
	if odds == 0 or odds == 1:
		print(int(count / 2))
	else:
		print('-1')


a = int(input())
for _ in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	odd = 0
	even = 0
	if c[0] % 2 == 1:
		even += 1
	for i in range(1, b):
		if i & 1:
			if c[i] % 2 == 0:
				odd += 1
		elif c[i] % 2 == 1:
			even += 1
	if odd == even:
		print(odd)
	else:
		print('-1')


def fun(list1):
	list2 = []
	for i in list1:
		if i % 2 == 0:
			list2.append(0)
		else:
			list2.append(1)
	counter = 0
	count_0 = list2.count(0)
	count_1 = list2.count(1)
	if count_0 == count_1 or count_0 == count_1 + 1:
		for i in range(0, len(list2), 2):
			if list2[i] == 0:
				counter += 1
		return count_0 - counter
	else:
		return -1
for i in range(int(input())):
	n = input()
	list1 = list(map(int, input().split()))
	print(fun(list1))


from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
from collections import Counter
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction
t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, stdin.readline().split()))
	evens = n // 2 + n % 2
	odds = n // 2
	(e, o, mismatch) = (0, 0, 0)
	for i in range(n):
		if i % 2 == 0:
			if nums[i] % 2 == 0:
				e += 1
			else:
				o += 1
				mismatch += 1
		elif nums[i] % 2 == 1:
			o += 1
		else:
			e += 1
			mismatch += 1
	if e != evens and o != odds:
		print(-1)
	else:
		print(mismatch // 2)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt0 = 0
	cnt1 = 0
	f = 0
	d0 = 0
	d1 = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			f += 1
		if i % 2 == 0:
			cnt0 += 1
		if i % 2 != 0:
			cnt1 += 1
		if arr[i] % 2 == 0:
			d0 += 1
		if arr[i] % 2 != 0:
			d1 += 1
	if d0 == cnt0 and d1 == cnt1:
		print(f // 2)
	else:
		print(-1)


def solve(array):
	rem0 = 0
	rem1 = 0
	for i in range(len(array)):
		if i % 2 == array[i] % 2:
			pass
		elif i % 2 == 0:
			rem0 += 1
		else:
			rem1 += 1
	if rem0 == rem1:
		return rem0
	else:
		return -1
N = int(input())
list = []
for i in range(N):
	l = int(input())
	temp = [int(x) for x in input().split()]
	list.append(temp)
for i in range(N):
	print(solve(list[i]))


t = int(input())
for _ in range(t):
	n = int(input())
	count = 0
	evenC = 0
	oddC = 0
	array = list(map(int, input().strip().split()))
	for i in range(len(array)):
		if array[i] % 2 == 0:
			evenC += 1
		else:
			oddC += 1
	if evenC == oddC or evenC == oddC + 1:
		for i in range(len(array)):
			if i % 2 == 0 and array[i] % 2 != 0:
				count += 1
			elif i % 2 == 1 and array[i] % 2 != 1:
				count += 1
		if count % 2 == 0:
			print(count // 2)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	odd = 0
	even = 0
	wrong = 0
	for i in range(n):
		if i % 2 != l[i] % 2 or (i == 0 and l[i] % 2 != 0):
			wrong += 1
			if l[i] % 2 == 0:
				even += 1
			else:
				odd += 1
	if wrong == 0:
		print(0)
	elif wrong % 2 != 0:
		print(-1)
	elif odd == even:
		print(even)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	flag = False
	j = 0
	while j < n:
		if l[j] % 2 != j % 2:
			flag = False
			for k in range(j + 1, n):
				if l[k] % 2 != k % 2:
					if l[j] % 2 == k % 2 and l[k] % 2 == j % 2:
						c = c + 1
						flag = True
						t = l[j]
						l[j] = l[k]
						l[k] = t
						break
					else:
						flag = False
						continue
			if flag == False:
				break
		else:
			flag = True
		j = j + 1
	if flag == False:
		print(-1)
	else:
		print(c)


t = int(input())
while t:
	n = int(input())
	a = [int(x) for x in input().split()]
	rem = [x % 2 for x in a]
	if sum(rem) != int(n / 2):
		print('-1\n')
	else:
		res = 0
		for i in range(0, n, 2):
			res += a[i] % 2
		print(str(res) + '\n')
	t -= 1


import math
import bisect
import sys
T = int(input())
for t in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(N):
		if i % 2 == 0 and A[i] % 2 == 1:
			e += 1
		elif i % 2 == 1 and A[i] % 2 == 0:
			o += 1
	if e == o:
		print(e)
	else:
		print(-1)


I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	l = I()
	o = 0
	e = 0
	for i in range(n):
		if l[i] % 2 != i % 2:
			if (i + 1) % 2 == 0:
				e += 1
			else:
				o += 1
	if o == e:
		print(o)
	else:
		print(-1)


def main():
	n = int(input())
	lst = list(map(int, input().split()))
	b0 = 0
	b1 = 0
	for i in range(n):
		if i % 2 and lst[i] % 2 == 0:
			b0 += 1
		if i % 2 == 0 and lst[i] % 2:
			b1 += 1
	if b0 != b1:
		print(-1)
	else:
		print(b0)
for t in range(int(input())):
	main()


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	ind = 0
	el = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if i % 2:
				ind += 1
			else:
				el += 1
	if el != ind:
		print(-1)
	else:
		print(el)
tt = int(input())
for test in range(tt):
	solve()


def solve(arr):
	even = 0
	odd = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			if arr[i] % 2 != 0:
				even += 1
		elif arr[i] % 2 == 0:
			odd += 1
	if odd == even:
		return even
	else:
		return -1
test = int(input())
for i in range(test):
	s = input()
	arr = list(map(int, input().split()))
	print(solve(arr))


for i in range(int(input())):
	a = int(input())
	t = list(map(int, input().split()))
	if a == 0:
		if t[0] % 2 == 0:
			print(0)
		else:
			print(-1)
	else:
		s = 0
		x = 0
		for k in range(a):
			if k % 2 == 0:
				if t[k] % 2 == 0:
					pass
				else:
					u = 0
					for j in range(k + 1, a):
						if j % 2 != 0:
							if t[j] % 2 == 0:
								(t[k], t[j]) = (t[j], t[k])
								s += 1
								u += 1
								break
							else:
								pass
					if u == 0:
						print(-1)
						x += 1
						break
			elif t[k] % 2 != 0:
				pass
			else:
				u = 0
				for j in range(k + 1, a):
					if j % 2 == 0:
						if t[j] % 2 != 0:
							(t[k], t[j]) = (t[j], t[k])
							s += 1
							u += 1
							break
						else:
							pass
				if u == 0:
					print(-1)
					x += 1
					break
		if x == 0:
			print(s)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	eid = oid = c = eno = ono = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			c += 1
		if a[i] % 2 == 0:
			eno += 1
		else:
			ono += 1
		if i % 2 == 0:
			eid += 1
		else:
			oid += 1
	if c == 0:
		ans = 0
	elif eid == eno and oid == ono:
		ans = c // 2
	else:
		ans = -1
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = [int(i) for i in input().split()]
		odd = even = 0
		for i in range(n):
			if i % 2 != a[i] % 2:
				if i % 2 == 0:
					even += 1
				else:
					odd += 1
		if even == odd:
			print(even)
		else:
			print(-1)
main()


for _ in range(int(input())):
	n = int(input())
	m = map(int, input().split())
	even = []
	odd = []
	for i in range(n):
		num = next(m)
		if i % 2 == 0:
			if num % 2 == 0:
				even.append(0)
			else:
				even.append(1)
		elif num % 2 == 0:
			odd.append(1)
		else:
			odd.append(0)
	ec = even.count(1)
	oc = odd.count(1)
	print(-1 if ec != oc else ec)


import collections
tests = int(input())
for _ in range(tests):
	n = int(input())
	a = [int(a) for a in input().strip().split(' ')]
	evens = 0
	odds = 0
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				evens += 1
			else:
				odds += 1
	if evens == odds:
		print(evens)
	else:
		print(-1)


import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
for i in range(r()):
	n = r()
	a = rl()
	op = 0
	ep = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				ep += 1
		elif a[i] % 2 != 1:
			op += 1
	if op == ep:
		print(op)
	else:
		print(-1)


def func(arr):
	c = 0
	l = []
	for i in range(n):
		if i % 2 != arr[i] % 2:
			c += 1
			l.append(arr[i] % 2)
	if l.count(0) == l.count(1):
		print(c // 2)
	else:
		print(-1)
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	func(arr)


t = int(input())
cnt = 0
while cnt < t:
	cnt += 1
	n = int(input())
	a = [int(i) for i in input().split()]
	good = sum((i % 2 == 0 and a[i] % 2 == 0 for i in range(n)))
	tot_odd = sum((a[i] % 2 == 0 for i in range(n)))
	if tot_odd != (n + 1) // 2:
		print(-1)
		continue
	else:
		print(abs(tot_odd - good))


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 200010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]
spf[0] = spf[1] = -1

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	n = int(input())
	a = arrIN()
	o = e = 0
	for i in range(n):
		if i % 2:
			o += 1 - a[i] % 2
		else:
			e += a[i] % 2
	if o != e:
		print(-1)
	else:
		print(o)


t = int(input())
for i in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	ev = 0
	od = 0
	for i in range(n):
		if i % 2 == 1:
			if ar[i] % 2 == 0:
				od += 1
		elif ar[i] % 2 == 1:
			ev += 1
	if od != ev:
		print(-1)
	else:
		print(od)


for t in range(int(input())):
	n = int(input())
	aa = [int(s) for s in input().split(' ')]
	bad = [0, 0]
	for (i, v) in enumerate(aa):
		if i % 2 != v % 2:
			bad[i % 2] += 1
	print(-1 if bad[0] != bad[1] else bad[0])


case = int(input())
for i in range(0, case):
	length = int(input())
	numberList = [int(x) for x in input().split()]
	(OddButGotEven, EvenButGotOdd) = (0, 0)
	Even = 0
	for n in range(0, length):
		if n % 2:
			if not numberList[n] % 2:
				OddButGotEven += 1
		elif numberList[n] % 2:
			EvenButGotOdd += 1
	if EvenButGotOdd == OddButGotEven:
		answer = EvenButGotOdd
	else:
		answer = -1
	print(answer)


q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	(n1, n2) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			n1 += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			n2 += 1
	if n1 == n2:
		print(n1)
	else:
		print(-1)


from math import gcd

def f():
	x = int(input())
	s = list(map(int, input().split()))
	sm = 0
	a = 0
	b = 0
	for n in range(x):
		if s[n] % 2 != n % 2:
			if n % 2 == 1:
				a += 1
			else:
				b += 1
	if a != b:
		print(-1)
		return
	print(a)
for n in range(int(input())):
	f()


for t in range(int(input())):
	n = int(input())
	a = [int(num) for num in input().split()]
	nech = []
	ch = []
	if len(a) == 1 and a[0] % 2 == 1:
		print(-1)
	else:
		for j in range(len(a)):
			if a[j] % 2 != 0 and j % 2 == 0:
				ch.append(j)
			elif a[j] % 2 == 0 and j % 2 != 0:
				nech.append(j)
		if len(nech) == len(ch):
			print(len(ch))
		else:
			print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	ce = 0
	co = 0
	for i in range(n):
		if i % 2 == a[i] % 2:
			pass
		elif i % 2 == 0:
			ce += 1
		else:
			co += 1
	if ce == co:
		print(ce)
	else:
		print(-1)


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	e = 0
	o = 0
	for i in range(n):
		if a[i] % 2 == 0 and i % 2 == 1:
			o += 1
		elif a[i] % 2 == 1 and i % 2 == 0:
			e += 1
	if o != e:
		print(-1)
	else:
		print(e)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	teven = []
	todd = []
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				teven.append(i)
			else:
				todd.append(i)
	if len(teven) == len(todd):
		print(len(teven))
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	m = [int(x) for x in input().split()]
	c01 = c10 = 0
	for (i, x) in enumerate(m):
		t = (i % 2, x % 2)
		if t == (0, 1):
			c01 += 1
		if t == (1, 0):
			c10 += 1
	if c01 == c10:
		print(c10)
	else:
		print(-1)


import math
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	for i in range(n):
		a[i] = a[i] % 2
	if sum(a) == n // 2:
		ans = 0
		for i in range(n):
			ans += abs(a[i] - i % 2)
		print(ans // 2)
	else:
		print(-1)


n = int(input())
for i in range(0, n):
	a = int(input())
	c = d = 0
	l = list(map(int, input().split()))
	if a == 1:
		if l[0] % 2 == 0:
			print(0)
		else:
			print(-1)
	else:
		for j in range(0, a):
			if j % 2 == 1:
				if l[j] % 2 == 0:
					c = c + 1
			elif l[j] % 2 == 1:
				d = d + 1
		if c == d:
			print(c)
		else:
			print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	evens = sum([x % 2 for x in a])
	if evens != n // 2:
		print(-1)
	else:
		print(len([i for i in range(0, n, 2) if a[i] & 1]))


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		n = II()
		aa = LI()
		cnt = [0] * 2
		for (i, a) in enumerate(aa):
			if i & 1 != a & 1:
				cnt[i & 1] += 1
		if cnt[0] == cnt[1]:
			print(cnt[0])
		else:
			print(-1)
main()


def solve(arr):
	(a, b) = (0, 0)
	for (i, v) in enumerate(arr):
		if i % 2 == v % 2:
			continue
		if i % 2 and (not v % 2):
			a += 1
		else:
			b += 1
	if a == b:
		return a
	else:
		return -1

def main():
	inp = lambda : [int(x) for x in input().split()]
	inn = lambda : int(input())
	t = inn()
	for _ in range(t):
		(_, a) = (inn(), inp())
		print(solve(a))
main()


import sys

def calculate(numbers):
	invalidOddIdxCount = 0
	invalidEvenIdxCount = 0
	for (idx, rawNumber) in enumerate(numbers):
		number = int(rawNumber)
		if number % 2 == 0:
			if idx % 2 != 0:
				invalidEvenIdxCount += 1
		elif idx % 2 != 1:
			invalidOddIdxCount += 1
	if invalidEvenIdxCount == invalidOddIdxCount:
		return int((invalidEvenIdxCount + invalidOddIdxCount) / 2)
	else:
		return -1

def iteratedTestCases(totalInput):
	for idx in range(0, int(totalInput)):
		sys.stdin.readline()
		secondInput = sys.stdin.readline()
		yield secondInput.split(' ')
numOfInput = sys.stdin.readline()
for lineInput in iteratedTestCases(numOfInput):
	result = calculate(lineInput)
	print(result)


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	d = defaultdict(int)
	for i in range(n):
		if i % 2 == arr[i] % 2:
			continue
		d[i % 2] += 1
	if d[0] == d[1]:
		print(d[0])
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	pp = []
	p = []
	a = list(map(int, input().split()))
	c1 = 0
	c0 = 0
	for j in range(0, n):
		pp.append(a[j] % 2)
		p.append(j % 2)
	if pp == p:
		print(0)
	else:
		for j in range(n):
			if pp[j] != p[j]:
				if pp[j] == 1:
					c1 += 1
				else:
					c0 += 1
		if c1 == c0:
			print(c1)
		else:
			print(-1)


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7

def solve():
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	odd = 0
	even = 0
	ans = -1
	correct = 0
	for i in range(n):
		if a[i] % 2 == 0:
			even += 1
			if i % 2 == 0:
				correct += 1
		else:
			odd += 1
			if i % 2 == 1:
				correct += 1
	if odd == n // 2:
		ans = (n - correct) // 2
		print(ans)
	else:
		print(ans)
t = 1
t = int(stdin.readline())
for _ in range(t):
	solve()


from sys import stdin, stdout

def input():
	return stdin.readline()

def prin(x):
	return stdout.write(str(x) + '\n')
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(k) for k in input().split()]
	(c1, c2) = (0, 0)
	for i in range(n):
		if i & 1 == 1 and a[i] & 1 != 1:
			c1 += 1
		if i & 1 != 1 and a[i] & 1 == 1:
			c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)


t = input()
t = int(t)
while t > 0:
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	(even_cnt, odd_cnt) = (0, 0)
	for i in a:
		if i % 2 == 0:
			even_cnt += 1
		else:
			odd_cnt += 1
	if n % 2 != 0 and odd_cnt > even_cnt:
		print(-1)
	elif n % 2 == 0 and odd_cnt != even_cnt:
		print(-1)
	else:
		(mis_odd, mis_even) = (0, 0)
		for (idx, val) in enumerate(a):
			if idx % 2 == 0 and val % 2 != 0:
				mis_even += 1
			elif idx % 2 != 0 and val % 2 == 0:
				mis_odd += 1
		if mis_even != mis_odd:
			print(-1)
		else:
			print(mis_even)
	t -= 1


import sys
input = sys.stdin.readline
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(councils, a, k):
	summ = 0
	for x in a:
		summ += min(x, councils)
	return summ // councils >= k
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys

def solve():
	n = int(input())
	a = list(read())
	even = math.ceil(n / 2)
	odd = math.floor(n / 2)
	count_even = 0
	count_odd = 0
	for x in a:
		if x % 2 == 0:
			count_even += 1
		else:
			count_odd += 1
	if count_even != even or count_odd != odd:
		print(-1)
		return
	c = 0
	for (i, x) in enumerate(a):
		if i % 2 != x % 2:
			c += 1
	print(c // 2)
for _ in range(int(input())):
	solve()


for x in range(int(input())):
	s = input()
	arr = list(map(int, input().split()))
	count = 0
	a = 0
	b = 0
	for c in arr:
		if c % 2 == count % 2:
			count += 1
			continue
		if c % 2 == 0:
			a += 1
		else:
			b += 1
		count += 1
	if a == b:
		print(a)
	else:
		print(-1)


t = int(input())
for y in range(t):
	n = int(input())
	col1 = [0, 0]
	col2 = [0, 0]
	diff = 0
	a = input().split(' ')
	for i in range(n):
		x = int(a[i])
		col1[i % 2] += 1
		col2[x % 2] += 1
		if i % 2 != x % 2:
			diff += 1
	ans = diff // 2
	if col1 != col2:
		ans = -1
	print(ans)


def sol():
	t = int(input())
	for tt in range(t):
		n = int(input())
		A = [int(item) for item in input().split()]
		ef = 0
		of = 0
		for i in range(n):
			if i % 2 == 0 and A[i] % 2 != 0:
				ef += 1
			if i % 2 == 1 and A[i] % 2 == 0:
				of += 1
		if ef == of:
			print(ef)
		else:
			print(-1)
sol()


import math
import sys
from collections import Counter
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		one_cnt = n // 2
		zero_cnt = n - one_cnt
		for (idx, num) in enumerate(arr):
			if num % 2 != idx % 2:
				continue
			if idx % 2 == 0:
				zero_cnt -= 1
			else:
				one_cnt -= 1
		if one_cnt != zero_cnt:
			print(-1)
			continue
		print(one_cnt)
main()


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	p = 0
	q = 0
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				p = p + 1
			else:
				q = q + 1
	if p != q:
		print('-1')
	else:
		print(p)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	s1 = 0
	s2 = 0
	for i in range(n):
		if l[i] % 2 != i % 2:
			c += 1
			if l[i] % 2 == 0:
				s1 += 1
			else:
				s2 += 1
	if c % 2 == 0:
		if s1 == s2:
			print(c // 2)
		else:
			print('-1')
	else:
		print('-1')


def good_array(l):
	s0 = []
	for i in range(len(l)):
		if i % 2 != int(l[i]) % 2:
			s0.append(int(l[i]))
	odd = 0
	even = 0
	for i in s0:
		if i % 2 == 1:
			odd += 1
		else:
			even += 1
	if odd != even:
		return -1
	else:
		return int(len(s0) / 2)
n = int(input())
list = []
for i in range(n):
	m = int(input())
	s = str(input())
	l = s.split()
	list.append(l)
for i in list:
	print(good_array(i))


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	odds = 0
	even = 0
	for i in range(n):
		if a[i] % 2 and i % 2 == 0:
			odds += 1
		elif a[i] % 2 == 0 and i % 2:
			even += 1
	if odds == even:
		print(odds)
	else:
		print(-1)


test = int(input())
while test > 0:
	test -= 1
	n = int(input())
	a = list(map(int, input().split()))
	d1 = int(0)
	d2 = int(0)
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				d1 += 1
			else:
				d2 += 1
	if d1 != d2:
		print('-1')
	else:
		print('%d' % d1)


for _ in range(int(input())):
	n = int(input())
	l = []
	flag = 0
	c = 0
	l = list(map(int, input().split()))
	for i in range(0, n, 2):
		if l[i] & 1:
			c += 1
	for i in range(1, n, 2):
		if l[i] & 1 == 0:
			flag += 1
	if flag == 0 and c == 0:
		print(0)
	elif flag == 0 and c != 0 or (flag != 0 and c == 0) or flag != c:
		print(-1)
	elif flag == c:
		print(c)


def evenarray():
	ans = True
	for i in range(length):
		if i % 2 == arr[i] % 2:
			pass
		else:
			ans = False
			return ans
	return ans
for i in range(int(input())):
	ycounter = 0
	icounter = 0
	placeholder = ''
	length = int(input())
	arr = list(map(int, input().split()))
	if evenarray() == True:
		print(0)
	else:
		for i in range(length):
			if i % 2 == 1 and arr[i] % 2 == 0:
				icounter += 1
		for y in range(length):
			if y % 2 == 0 and arr[y] % 2 == 1:
				ycounter += 1
		if (icounter + ycounter) % 2 == 0 and ycounter == icounter:
			print(int((icounter + ycounter) / 2))
		else:
			print(-1)


import math
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	y = 0
	z = 0
	w = 0
	for j in range(n):
		if a[j] % 2 == 0:
			x += 1
			if j % 2 != 0:
				z += 1
		else:
			y += 1
			if j % 2 == 0:
				w += 1
	if n % 2 == 0 and x != y:
		print(-1)
	elif n % 2 != 0 and x != y + 1:
		print(-1)
	elif z == w:
		print(z)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	cnt1 = 0
	cnt2 = 0
	for i in range(n):
		if i % 2 == 0 and ls[i] % 2 != 0:
			cnt1 += 1
		elif i % 2 != 0 and ls[i] % 2 == 0:
			cnt2 += 1
	if cnt1 == cnt2:
		print(cnt1)
	else:
		print(-1)


t = int(input())
for i in range(t):
	l = int(input())
	s = list(map(int, input().split(' ')))
	count = 0
	count2 = 0
	for j in range(l):
		if s[j] % 2 != j % 2 and j % 2 == 1:
			count += 1
		elif s[j] % 2 != j % 2 and j % 2 == 0:
			count2 += 1
	if count == count2:
		print(count)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]
	evens = [e for e in arr if e % 2 == 0]
	odds = [o for o in arr if o % 2 == 1]
	if len(arr) // 2 != len(odds):
		print('-1')
	else:
		count = 0
		for k in range(len(arr)):
			if k % 2 != arr[k] % 2:
				count += 1
		swaps = count // 2
		print(swaps)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	codd = 0
	ceven = 0
	for i in range(n):
		if i % 2 == 0:
			if arr[i] % 2 != 0:
				ceven += 1
		elif arr[i] % 2 != 1:
			codd += 1
	if codd == ceven:
		print(codd)
	else:
		print(-1)


def f(a):
	even = []
	odd = []
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			if a[i] % 2 == 0:
				even.append(a[i])
			else:
				odd.append(a[i])
	if len(even) == len(odd):
		return len(even)
	else:
		return -1
for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(f(arr))


from sys import stdin, stdout
from collections import defaultdict
test = int(stdin.readline())
for _ in range(test):
	N = int(stdin.readline())
	A = [int(x) for x in stdin.readline().split()]
	odd = 0
	even = 0
	for i in range(N):
		if i & 1:
			if A[i] & 1 ^ 1:
				odd += 1
				continue
		elif A[i] & 1:
			even += 1
			continue
	if odd != even:
		print(-1)
	else:
		print(odd)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(c) for c in input().split()]
	evenwrong = 0
	oddwrong = 0
	for i in range(len(arr)):
		if i & 1 == arr[i] & 1:
			continue
		if i % 2 == 0:
			evenwrong += 1
		else:
			oddwrong += 1
	if evenwrong == oddwrong:
		print(evenwrong)
	else:
		print(-1)


import sys
input = sys.stdin.readline
t = int(input())
for r in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in l:
		if i % 2 == 0:
			even += 1
		else:
			odd += 1
	if n % 2 == 0 and odd != even or (n % 2 != 0 and odd + 1 != even):
		print(-1)
	else:
		count = 0
		for i in range(n):
			if i % 2 == 0 and l[i] % 2 == 0 or (i % 2 != 0 and l[i] % 2 != 0):
				continue
			for j in range(i + 1, n):
				if l[i] % 2 == 0:
					if j % 2 == 0 and l[j] % 2 != 0:
						(l[i], l[j]) = (l[j], l[i])
						count += 1
						break
				elif j % 2 != 0 and l[j] % 2 == 0:
					(l[i], l[j]) = (l[j], l[i])
					count += 1
					break
		print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().strip().split()))
	(r, e, o) = (0, 0, 0)
	for i in range(n):
		if i % 2 != l[i] % 2:
			r += 1
			if l[i] & 1:
				o += 1
			elif l[i] % 2 == 0:
				e += 1
	if r % 2 or e != o:
		print('-1')
	else:
		print(int(r / 2))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c_chet = 0
	c_nechet = 0
	for i in range(n):
		if a[i] % 2 == 1 and i % 2 == 0:
			c_nechet += 1
		elif a[i] % 2 == 0 and i % 2 == 1:
			c_chet += 1
	if c_nechet == c_chet:
		print(c_chet)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	badevens = 0
	badodd = 0
	correct = 0
	bad = []
	for i in range(n):
		if i % 2 == a[i] % 2:
			correct += 1
		else:
			bad.append(i)
			if i % 2 == 0:
				badevens += 1
			else:
				badodd += 1
	if badevens == badodd:
		print(len(bad) // 2)
	else:
		print('-1')


t = int(input())
for _ in range(t):
	n = int(input())
	count_0 = 0
	count_1 = 0
	i = 0
	for x in input().split():
		if i % 2 != int(x) % 2:
			if i % 2 == 0:
				count_0 += 1
			else:
				count_1 += 1
		i += 1
	if count_0 != count_1:
		print('-1')
	else:
		print(count_0)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	n = input()
	ls = get_list()
	(c0, c1) = (0, 0)
	for (i, val) in enumerate(ls):
		if i % 2 != val % 2:
			if i % 2:
				c1 += 1
			else:
				c0 += 1
	if c0 == c1:
		return c0
	return -1

def main():
	print(solve())
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


T = int(input())
for u in range(1, T + 1):
	N = int(input())
	a = [int(x) for x in input().split()]
	even = 0
	bad = 0
	for i in range(0, len(a)):
		if i % 2 != a[i] % 2:
			bad = bad + 1
		if a[i] % 2 == 0:
			even = even + 1
	if len(a) % 2 == 0:
		if even == len(a) / 2:
			print(int(bad / 2))
		else:
			print(-1)
	elif even == (len(a) + 1) / 2:
		print(int(bad / 2))
	else:
		print(-1)


T = int(input())
for _ in range(T):
	N = int(input())
	Arr = list(map(int, input().split()))
	Parity = 0
	Incorrect = 0
	for (i, elt) in enumerate(Arr):
		if i % 2 != elt % 2:
			Incorrect += 1
			Parity += elt % 2 - 0.5
	if Parity != 0:
		print(-1)
	else:
		print(Incorrect // 2)


t = int(input())
for k in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	cnt = 0
	e = 0
	o = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			cnt += 1
		if arr[i] % 2 == 0:
			e += 1
		elif arr[i] % 2 != 0:
			o += 1
	if cnt % 2 == 0:
		if n % 2 == 0:
			if e == o:
				print(cnt // 2)
			else:
				print(-1)
		elif e == o + 1:
			print(cnt // 2)
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	e = 0
	o = 0
	while i < len(l):
		x = l[i]
		if i % 2 == 0 and x % 2 == 1:
			o = o + 1
		if i % 2 == 1 and x % 2 == 0:
			e = e + 1
		i = i + 1
	if e == o:
		print(e)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	E = 0
	m = 0
	for i in range(n):
		if a[i] % 2 == 0:
			if i % 2 == 1:
				E += 1
				m += 1
		elif i % 2 == 0:
			E -= 1
	if E == 0:
		print(m)
	else:
		print(-1)


import sys
input = sys.stdin.readline
from collections import *
import math
t = int(input())
while t:
	t -= 1
	n = int(input())
	res = 0
	count1 = 0
	count2 = 0
	arr = [int(x) for x in input().split()]
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 == 1:
			count1 += 1
		elif i % 2 == 1 and arr[i] % 2 == 0:
			count2 += 1
	if count1 == count2:
		print(count1)
	else:
		print(-1)


import sys
input = sys.stdin.readline
INF = 10 ** 18
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	(we, wo) = (0, 0)
	for (i, v) in enumerate(A):
		if i % 2 != v % 2:
			if i % 2:
				wo += 1
			else:
				we += 1
	if wo != we:
		print(-1)
	else:
		print(wo)


t = int(input())
for q in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	(c1, c2) = (0, 0)
	for i in range(0, len(l)):
		if i % 2 == 0 and l[i] % 2 == 1:
			c1 += 1
		elif i % 2 == 1 and l[i] % 2 == 0:
			c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)


listy = []
n = int(input())
for i in range(0, n):
	c1 = 0
	c0 = 0
	l = int(input())
	num = input()
	listy = num.split()
	lent = len(listy)
	for j in range(0, lent):
		if j % 2 == 0:
			if int(listy[j]) % 2 != 0:
				c1 += 1
		elif int(listy[j]) % 2 == 0:
			c0 += 1
	if c0 == c1:
		print(c0)
	else:
		print('-1')


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	o = 0
	e = 0
	b = 0
	if n % 2 == 0:
		for i in range(n):
			if a[i] % 2 == 0:
				e += 1
			else:
				o += 1
		if e == o:
			for i in range(n):
				if a[i] % 2 == 0 and i % 2 == 0 or (a[i] % 2 != 0 and i % 2 != 0):
					pass
				else:
					b += 1
		else:
			b = -1
	else:
		for i in range(n):
			if a[i] % 2 == 0:
				e += 1
			else:
				o += 1
		if e % 2 != o % 2 and e - o == 1:
			if n > 1 and e >= 1 and (o >= 1):
				for i in range(n):
					if a[i] % 2 == 0 and i % 2 == 0 or (a[i] % 2 != 0 and i % 2 != 0):
						pass
					else:
						b += 1
			elif n == 1 and e == 1:
				b = 0
			else:
				b = -1
		else:
			b = -1
	if b < 0:
		print(b)
	else:
		print(b // 2)


cases = int(input())
for _ in range(cases):
	n = int(input())
	a = list(map(int, input().split()))
	g = [0, 0]
	for i in range(0, n):
		if not a[i] & 1 == i & 1:
			g[i & 1] += 1
	if g[0] != g[1]:
		print(-1)
	else:
		print(g[0])


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	k = 0
	k1 = 0
	for j in range(n):
		if j % 2 == 0 and A[j] % 2 == 1:
			k += 1
			k1 += 1
		elif j % 2 == 1 and A[j] % 2 == 0:
			k -= 1
	if k == 0:
		print(k1)
	else:
		print(-1)


t = int(input())
for i in range(0, t):
	n = int(input())
	arr = list(map(int, input().split()))
	l = len(arr)
	cnt = 0
	odd = 0
	even = 0
	for j in range(0, l):
		if j % 2 != arr[j] % 2:
			cnt = cnt + 1
		if arr[j] % 2 == 0:
			even = even + 1
		else:
			odd = odd + 1
	if l % 2 == 0 and odd != even or (l % 2 != 0 and even != odd + 1):
		print(-1)
	else:
		print(int(cnt / 2))


arg = int(input())
for i in range(0, arg):
	n = int(input())
	l = list(map(int, input().strip().split()))
	even = 0
	odd = 0
	for k in l:
		if k % 2 == 0:
			even += 1
		else:
			odd += 1
	if n % 2 == 0:
		if even != odd:
			print(-1)
			continue
		else:
			coun = 0
			for k in range(0, n):
				if k % 2 != 0 and l[k] % 2 == 0:
					coun += 1
			print(coun)
	elif even - odd != 1:
		print(-1)
		continue
	else:
		coun = 0
		for k in range(0, n):
			if k % 2 != 0 and l[k] % 2 == 0:
				coun += 1
		print(coun)


for _ in range(int(input())):
	t = int(input())
	lst = list(map(int, input().split()))
	x = y = 0
	for i in range(t):
		if i % 2 != lst[i] % 2:
			if lst[i] % 2 == 0:
				x += 1
			else:
				y += 1
	if x != y:
		print(-1)
	else:
		print(x)


for _ in range(int(input())):
	n = int(input().strip())
	arr = list(map(int, input().strip().split(' ')))
	(odd, eve) = (0, 0)
	for a in arr:
		if a % 2 == 0:
			eve += 1
		else:
			odd += 1
	(rod, rev) = (0, 0)
	if n % 2 == 0:
		rod = rev = n // 2
	else:
		rod = n // 2
		rev = n // 2 + 1
	if rod == odd and eve == rev:
		(bev, bod) = (0, 0)
		for i in range(n):
			if arr[i] % 2 == 1 and i % 2 == 0:
				bev += 1
			elif arr[i] % 2 == 0 and i % 2 == 1:
				bod += 1
		if bev == bod:
			print(bev)
		else:
			print(-1)
	else:
		print(-1)


cases = int(input())
for _ in range(cases):
	n = int(input())
	(misplaced_odd, misplaced_even) = (0, 0)
	c = list(map(int, input().split()))
	for i in range(len(c)):
		if c[i] % 2 != i % 2:
			if c[i] & 1:
				misplaced_odd += 1
			else:
				misplaced_even += 1
	if misplaced_odd != misplaced_even:
		print(-1)
	else:
		print(misplaced_odd)


import sys
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
for _ in range(I()):
	n = I()
	l = li()
	count = 0
	o = 1
	e = 0
	while 1:
		while e < n and l[e] & 1 == 0:
			e += 2
		while o < n and l[o] & 1:
			o += 2
		if e < n and o < n:
			(l[e], l[o]) = (l[o], l[e])
			count += 1
		else:
			break
	for i in range(n):
		if l[i] & 1 != i & 1:
			print(-1)
			break
	else:
		print(count)


n = int(input())
for _ in range(n):
	input()
	a = list(map(int, input().split()))
	(c_e, c_n) = (0, 0)
	for (i, x) in enumerate(a):
		if i % 2 == 0 and x % 2 == 1:
			c_e += 1
		if i % 2 == 1 and x % 2 == 0:
			c_n += 1
	if c_e != c_n:
		print(-1)
	else:
		print(c_e)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c1 = 0
	c0 = 0
	w1 = 0
	w0 = 0
	ans = 0
	for i in range(n):
		temp = a[i] % 2
		if temp == i % 2:
			a[i] = 'v'
		else:
			a[i] = temp
			if temp == 0:
				w0 += 1
			else:
				w1 += 1
		if temp == 0:
			c0 += 1
		else:
			c1 += 1
		if w0 >= 1 and w1 >= 1:
			ans += 1
			w0 -= 1
			w1 -= 1
	if n % 2 == 0:
		if c0 == c1:
			print(ans)
		else:
			print(-1)
	elif c0 == c1 + 1:
		print(ans)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	eo = 0
	oe = 0
	for j in range(n):
		if (j - int(a[j])) % 2:
			if j % 2:
				oe += 1
			else:
				eo += 1
	if eo == oe:
		print(eo)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	lol = [int(n) for n in input().split()]
	e = 0
	o = 0
	mis = 0
	for i in lol:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
	if n % 2 == 0:
		for i in range(0, n, 2):
			if lol[i] % 2 != 0:
				mis += 1
			if lol[i + 1] % 2 == 0:
				mis += 1
	else:
		for i in range(0, n - 1, 2):
			if lol[i] % 2 != 0:
				mis += 1
			if lol[i + 1] % 2 == 0:
				mis += 1
		if lol[-1] % 2 != 0:
			mis += 1
	if n == 1:
		if lol[0] % 2 == 0:
			print(0)
		else:
			print(-1)
	elif n % 2 == 0:
		if e != o:
			print(-1)
		else:
			print(int(mis / 2))
	elif n % 2 != 0:
		if e != o + 1:
			print(-1)
		else:
			print(int(mis / 2))


try:
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		co = 0
		ce = 0
		for i in range(n):
			if i % 2 == 0:
				if l[i] % 2 != 0:
					ce += 1
			elif l[i] % 2 == 0:
				co += 1
		if co == ce:
			print(ce)
		else:
			print(-1)
except:
	pass


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ce = 0
	co = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				ce += 1
			else:
				co += 1
	if co == ce:
		print(co)
	else:
		print(-1)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	oo = 0
	ee = 0
	oe = 0
	eo = 0
	for j in range(n):
		if a[j] % 2 == 0 and j % 2 == 0:
			ee += 1
			continue
		if a[j] % 2 != 0 and j % 2 != 0:
			oo += 1
			continue
		if a[j] % 2 == 0 and j % 2 != 0:
			eo += 1
			continue
		if a[j] % 2 != 0 and j % 2 == 0:
			oe += 1
			continue
	if ee + oo == n:
		ans.append(0)
	elif eo == oe:
		ans.append(eo)
	else:
		ans.append(-1)
for an in ans:
	print(an)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) % 2 == i % 2 for (i, x) in enumerate(input().split())]
	t = [0, 0]
	for (i, e) in enumerate(a):
		if not e:
			t[i % 2] += 1
	if t[0] == t[1]:
		print(t[0])
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	countOdd = 0
	countEven = 0
	for i in range(n):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				countOdd += 1
		elif l[i] % 2 == 0:
			countEven += 1
	if countEven == countOdd:
		print(countEven)
	else:
		print(-1)


t = int(input())
while t:
	n = input()
	ls = list(map(int, input().split()))
	o = e = 0
	for i in range(int(n)):
		if i % 2 != ls[i] % 2:
			if ls[i] % 2:
				o += 1
			else:
				e += 1
	if o == e:
		print(o)
	else:
		print(-1)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	(count_odd, count_even) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			count_odd += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			count_even += 1
	if count_even == count_odd:
		print(count_odd)
	else:
		print(-1)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	tot = 0
	num = 0
	for (i, a) in enumerate(A):
		if i % 2 != a % 2:
			if a % 2 == 1:
				tot += 1
			else:
				tot -= 1
			num += 1
	if tot == 0:
		print(num // 2)
	else:
		print(-1)


test = int(input())
for _ in range(test):
	n = int(input())
	l = [int(x) for x in input().split()]
	even = odd = 0
	for i in range(n):
		if l[i] & 1 != i & 1:
			if l[i] & 1:
				odd += 1
			else:
				even += 1
	print(odd if odd == even else '-1')


t = int(input())
test_case = []
arr = []
err = []
err1 = []
for i in range(0, t):
	test_case.append(int(input()))
	arr.append([])
	arr[i] = [int(j) for j in input().split()]
	err.append([])
	err1.append([])
	for k in range(0, len(arr[i])):
		if arr[i][k] % 2 != k % 2:
			if arr[i][k] % 2 == 0:
				err[i].append(k)
			else:
				err1[i].append(k)
for i in range(0, t):
	if len(err[i]) != len(err1[i]):
		print(-1)
	else:
		print((len(err[i]) + len(err1[i])) // 2)


test = int(input())
for t in range(0, test):
	n = int(input())
	a = map(int, input().split())
	i = 0
	count = 0
	count1 = 0
	for b in a:
		if b & 1 == 0 and i & 1 == 1:
			count = count + 1
		elif b & 1 == 1 and i & 1 == 0:
			count1 = count1 + 1
		i = i + 1
	if count != count1:
		print(-1)
	else:
		print(count)


t = int(input())
for j in range(t):
	n = int(input())
	chet = 0
	nech = 0
	a = []
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				chet += 1
			else:
				nech += 1
	if chet == nech:
		print(chet)
	else:
		print('-1')


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	a = list(mints())
	c = [0, 0, 0, 0]
	for j in range(2):
		for i in range(j, n, 2):
			c[j * 2 + (a[i] & 1)] += 1
	if c[1] == c[2]:
		print(c[1])
	else:
		print(-1)
for i in range(mint()):
	solve()


def solve():
	T = int(input())
	for i in range(T):
		N = int(input())
		A = list(map(int, input().split()))
		bad_odd = 0
		bad_even = 0
		for j in range(N):
			if A[j] % 2 == j % 2:
				continue
			if A[j] % 2 == 0:
				bad_even += 1
			else:
				bad_odd += 1
		if bad_even == bad_odd:
			print(bad_even)
		else:
			print('-1')
solve()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ec = oc = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			ec += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			oc += 1
	if ec == oc:
		print(ec)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	(even, odd) = (0, 0)
	(a, b, p, q) = (0, 0, 0, 0)
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			even += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			odd += 1
	if even == odd:
		print(odd)
	else:
		print(-1)


n = input('')
n = int(n)
matrix = []
for i in range(n):
	C = int(input(''))
	entries = list(map(int, input().split()))
	matrix.append(entries)
for i in range(n):
	even_cnt = 0
	odd_cnt = 0
	for j in range(0, len(matrix[i]), 1):
		if j % 2 == 0:
			if matrix[i][j] % 2 != 0:
				even_cnt = even_cnt + 1
		elif matrix[i][j] % 2 == 0:
			odd_cnt = odd_cnt + 1
	total_cnt = odd_cnt + even_cnt
	if total_cnt == 0:
		print(0)
	elif total_cnt % 2 != 0:
		print(-1)
	elif even_cnt == odd_cnt:
		print(int(total_cnt / 2))
	else:
		print(-1)


import math
for i in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	we = 0
	wo = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2:
				wo += 1
			else:
				we += 1
	if wo != we:
		print(-1)
	else:
		print(wo)


t = int(input())
for q in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	even = 0
	odd = 0
	for i in range(n):
		if a[i] % 2 == 0 and i % 2 != 0:
			even += 1
		if a[i] % 2 != 0 and i % 2 == 0:
			odd += 1
	if even == odd:
		print(odd)
	else:
		print(-1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	od = 0
	ev = 0
	flag = True
	for i in a:
		if i % 2 == 0:
			od += 1
		else:
			ev += 1
	if n % 2 == 0:
		if od != ev:
			print(-1)
			flag = False
	elif od != ev + 1:
		print(-1)
		flag = False
	fa = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				fa += 1
		elif a[i] % 2 != 1:
			fa += 1
	if flag:
		print(fa // 2)


def main():
	noOfTestCases = int(input())
	for testCase in range(noOfTestCases):
		n = int(input())
		array = input().split()
		sumWrong1 = 0
		sumWrong0 = 0
		for i in range(len(array)):
			if int(array[i]) % 2 != i % 2:
				if int(array[i]) % 2 == 0:
					sumWrong0 += 1
				else:
					sumWrong1 += 1
		if sumWrong0 == sumWrong1:
			print(str(sumWrong0))
		else:
			print(str(-1))
main()


ans = []
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	swap_odd = 0
	swap_evn = 0
	for i in range(n):
		if i % 2 and a[i] % 2 != 1:
			swap_odd += 1
		elif i % 2 != 1 and a[i] % 2:
			swap_evn += 1
	if swap_odd != swap_evn:
		ans.append('-1')
	else:
		ans.append(str(swap_odd))
print('\n'.join(ans))


t = int(input())
for i in range(t):
	n = int(input())
	even = n // 2 + 1 if n % 2 else n // 2
	odd = n - even
	numE = numO = wrong = 0
	arr = list(map(int, input().split()))
	for each in range(n):
		if arr[each] % 2:
			numO += 1
		else:
			numE += 1
		if arr[each] % 2 != each % 2:
			wrong += 1
	if odd == numO and even == numE:
		print(wrong // 2)
	else:
		print(-1)


numCases = int(input())
for dummy in range(numCases):
	dumm = input()
	s = [int(i) for i in input().split(' ')]
	(evenInOdd, oddInEven) = (0, 0)
	switching = 1
	for i in s:
		considering = i % 2
		switching = switching ^ 1
		if considering == switching:
			continue
		elif considering == 1 and switching == 0:
			oddInEven += 1
		else:
			evenInOdd += 1
	if oddInEven == evenInOdd:
		print(oddInEven)
	else:
		print(-1)


t = int(input())

def f():
	n = int(input())
	a = list(map(int, input().split()))
	(c, b) = (0, 0)
	for i in range(n):
		if a[i] % 2 == 0:
			c += 1
	if n - c != n // 2:
		return -1
	else:
		for j in range(0, n, 2):
			if a[j] % 2 != 0:
				b += 1
		return b
while t > 0:
	print(f())
	t -= 1


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0:
			if l[i] % 2 == 0:
				pass
			else:
				even += 1
		if i % 2 == 1:
			if l[i] % 2 == 1:
				pass
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


for i in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	e = 0
	d = 0
	for i in range(0, len(l)):
		if l[i] % 2 != i % 2:
			if i % 2 == 0:
				e = e + 1
			else:
				d = d + 1
	if e == d:
		print(e)
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	arr = input().split()
	arr = [int(i) for i in arr]
	s = 0
	fl = False
	for i in range(n):
		c = 0
		for j in range(n):
			if j % 2 == arr[j] % 2:
				c += 1
			else:
				for k in range(j, n, 1):
					if j % 2 == arr[k] % 2 and arr[k] % 2 != k % 2:
						(arr[j], arr[k]) = (arr[k], arr[j])
						s += 1
						break
		if c == n:
			print(s)
			fl = True
			break
	if not fl:
		print(-1)


def task_B():
	t = int(input())
	for _ in range(t):
		n = int(input())
		array = list(map(int, input().split()))
		wrong_odd = 0
		wrong_even = 0
		for i in range(n):
			if i % 2 == 0:
				if array[i] % 2 != 0:
					wrong_even += 1
			elif array[i] % 2 == 0:
				wrong_odd += 1
		if wrong_even != wrong_odd:
			print(-1)
		else:
			print(wrong_odd)

def main():
	task_B()
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(odd, evn) = (0, 0)
	for i in range(n):
		if i % 2 == arr[i] % 2:
			continue
		elif i % 2 == 1:
			odd += 1
		else:
			evn += 1
	if odd == evn:
		print(odd)
	else:
		print(-1)


t = int(input())
ans = [0] * t
for j in range(t):
	ev1 = od1 = 0
	n = int(input())
	b = list(map(int, input().split()))
	a = [int(b[j] % 2 != j % 2) for j in range(n)]
	for i in range(n):
		if a[i] != 0:
			if i % 2 == 0:
				ev1 += 1
			else:
				od1 += 1
	if ev1 == od1:
		ans[j] = ev1
	else:
		ans[j] = -1
for i in ans:
	print(i)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().strip().split()))
	e = 0
	o = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			o += 1
		elif i % 2 == 1 and arr[i] % 2 != 1:
			e += 1
	if e == o:
		print(e)
	else:
		print(-1)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(mapi())
	cnt = [0] * 2
	for i in range(n):
		if a[i] % 2 != i % 2:
			cnt[i % 2] += 1
	if cnt[0] != cnt[1]:
		print(-1)
	else:
		print(cnt[0])


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	oddc = evenc = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			evenc += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			oddc += 1
	if oddc == evenc:
		print(oddc)
	else:
		print(-1)


n = int(input())
for i in range(n):
	size = int(input())
	arr = list(map(int, input().split()))
	fine = 0
	even = 0
	odd = 0
	for j in range(size):
		if j % 2 == 0:
			if arr[j] % 2 == 0:
				fine += 1
			else:
				even += 1
		elif arr[j] % 2 == 0:
			odd += 1
		else:
			fine += 1
	if even == odd:
		print(even)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	list2 = [i for (j, i) in enumerate(list1) if i % 2 == 1 and j % 2 == 0]
	list3 = [i for (j, i) in enumerate(list1) if i % 2 == 0 and j % 2 == 1]
	if len(list2) == len(list3):
		print(len(list2))
	else:
		print(-1)


t = int(input())
for t in range(t):
	p = int(input())
	lst = list(map(int, input().split()))
	o = e = 0
	for i in range(p):
		if i % 2 == 0 and lst[i] % 2 != 0:
			e += 1
		elif i % 2 != 0 and lst[i] % 2 == 0:
			o += 1
	if e == o:
		print(e)
	else:
		print('-1')


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	lt = [int(x) for x in input().split()]
	(e, o, c) = (0, 0, 0)
	for i in range(n):
		if i % 2 == 0 and lt[i] % 2 == 0 or (i % 2 != 0 and lt[i] % 2 != 0):
			c += 1
		elif i % 2 == 0:
			e += 1
		else:
			o += 1
	if o == 0 and e == 0:
		print(0)
	elif o == e:
		print(o)
	else:
		print(-1)


def func(arr):
	a = 0
	b = 0
	ans_arr = []
	for i in arr:
		if i % 2 == 0:
			b += 1
			ans_arr.append(0)
		else:
			a += 1
			ans_arr.append(1)
	if a == len(arr) // 2 and b == len(arr) - len(arr) // 2:
		idx = 0
		c = 0
		for i in ans_arr:
			if idx == 0:
				idx = 1
			else:
				if i != 1:
					c += 1
				idx = 0
		print(c)
	else:
		print(-1)
k = int(input())
for _ in range(k):
	l = input()
	arr = list(map(int, input().split()))
	func(arr)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(e, o) = (a[::2], a[1::2])
	ewrong = []
	owrong = []
	for i in range(len(a)):
		if i % 2 == 0 and a[i] % 2 != 0:
			owrong.append([a[i], i])
		if i % 2 == 1 and a[i] % 2 == 0:
			ewrong.append([a[i], i])
	print(len(ewrong) if len(ewrong) == len(owrong) else -1)


from sys import stdin
tc = int(stdin.readline())
for t in range(tc):
	n = int(stdin.readline())
	num = [int(x) for x in stdin.readline().strip().split()]
	(even, odd) = (0, 0)
	if len(num) == 1:
		if num[-1] & 1 == 0:
			print(0)
		else:
			print(-1)
	else:
		for i in range(len(num)):
			if i & 1 == 0 and num[i] & 1 != 0:
				even += 1
			if i & 1 == 1 and num[i] & 1 != 1:
				odd += 1
		if odd != even:
			print(-1)
		else:
			print(min(odd, even))


t = int(input())
for q in range(t):
	n = int(input())
	entrada = list(map(int, input().split(' ')))
	par = 0
	impar = 0
	for k in range(n):
		if entrada[k] % 2 == 0 and k % 2 == 1:
			par += 1
		if entrada[k] % 2 == 1 and k % 2 == 0:
			impar += 1
	if par == impar:
		print(par)
	else:
		print(-1)


n = int(input())
for i in range(n):
	k = int(input())
	ch = 0
	nch = 0
	a = [int(i) for i in input().split()]
	for j in range(k):
		if a[j] % 2 != j % 2:
			ch += 1
			if a[j] % 2 == 1:
				nch += 1
	if nch * 2 == ch:
		print(ch // 2)
	else:
		print(-1)


from sys import stdin, stdout
from math import pi
Pi = lambda x: stdout.write(str(x) + '\n')
Ps = lambda x: stdout.write(str(x))
S = lambda x: x * (x + 1) // 2
I = lambda x: 1 + 2 * x
R = lambda : stdin.readline()
Ri = lambda x: map(int, x.split())
Rs = lambda x: map(str, x.split())
Rf = lambda x: map(float, x.split())
char = lambda x, y: ord(x) - ord(y)
gcd = lambda a, b: a if b == 0 else gcd(b, a % b)
lcm = lambda a, b: a * b // gcd(a, b)
distance = lambda a, b, c, d: (a - c) ** 2 + (b - d) ** 2
MaxN = int(1000000.0) + 10
mod = int(1000000000.0) + 7

def main():
	for x in stdin:
		cases = int(x)
		for t in range(cases):
			n = int(R())
			A = list(Ri(R()))
			sw = 1
			even = 0
			for x in A:
				if x % 2 == 0:
					even += 1
			if even != n // 2 + n % 2:
				Pi(-1)
				continue
			if n == 1:
				if A[0] % 2 == 0:
					Pi(0)
				else:
					Pi(-1)
			else:
				c = 0
				for i in range(n):
					if i % 2 != A[i] % 2:
						c += 1
				ans = c // 2 + c % 2
				Pi(ans)
main()


t = int(input())
for z in range(t):
	n = int(input())
	list = [int(i) for i in input().split()]
	(odd_no, even_no) = (0, 0)
	for i in range(n):
		if list[i] % 2 == 0:
			even_no += 1
		else:
			odd_no += 1
	if n % 2 == 0 and int(n / 2) != odd_no:
		print('-1')
		continue
	elif n % 2 == 1 and int(n / 2) != odd_no:
		print('-1')
		continue
	count = 0
	for i in range(n):
		if i % 2 == 0 and list[i] % 2 == 1:
			count += 1
		elif i % 2 == 1 and list[i] % 2 == 0:
			count += 1
	print(int(count / 2))


t = int(input())
for i in range(0, t):
	n = int(input())
	l = list(map(int, input().strip().split(' ')))
	count = 0
	for j in range(0, n):
		if l[j] % 2 == 1:
			count += 1
	if count == n // 2:
		num = 0
		for k in range(0, n):
			if k % 2 != l[k] % 2:
				num += 1
		print(num // 2)
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	c0 = 0
	c1 = 0
	for i in range(n):
		if i % 2 == 0:
			if s[i] % 2 == 1:
				c1 += 1
		elif s[i] % 2 == 0:
			c0 += 1
	if c1 == c0:
		print(c1)
	else:
		print('-1')


for i in range(int(input())):
	n = int(input())
	a = [int(elem) for elem in input().split()]
	(counter1, counter2) = (0, 0)
	for i in range(n):
		if a[i] % 2 == 1 and i % 2 == 0:
			counter1 += 1
		if a[i] % 2 == 0 and i % 2 == 1:
			counter2 += 1
	if counter1 != counter2:
		print(-1)
	else:
		print(counter1)


t = int(input())

def f(n, a):
	i = 0
	j = 0
	for k in range(n):
		if k % 2 == 0:
			if a[k] % 2 != 0:
				i += 1
		elif a[k] % 2 == 0:
			j += 1
	if i == j:
		return i
	return -1
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(f(n, a))


t = int(int(input('')))
while t > 0:
	n = int(input(''))
	array = list(map(int, input().split()))
	odd_count = 0
	even_count = 0
	for i in range(n):
		if i % 2 == 0:
			if array[i] % 2 == 0:
				even_count += 1
		elif array[i] % 2 != 0:
			odd_count += 1
	changes1 = n // 2 + n % 2 - even_count
	changes2 = n // 2 - odd_count
	if changes1 == changes2:
		print(changes1)
	else:
		print(-1)
	t -= 1


def fun(s):
	o = 0
	c = 0
	for i in range(len(s)):
		if s[i] % 2 != i % 2:
			c += 1
		if s[i] % 2 != 0:
			o += 1
	if o == len(s) // 2 and c % 2 == 0:
		return c // 2
	return -1
n = int(input())
x = []
for i in range(n):
	t = input()
	x.append(list(map(int, input().split())))
for i in range(n):
	print(fun(x[i]))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	(eve, odd) = (0, 0)
	for i in a:
		if i % 2 == 0:
			eve += 1
		else:
			odd += 1
	if n == 1 and a[0] % 2 != 0:
		print('-1')
	elif n % 2 == 0 and eve != odd:
		print('-1')
	elif n % 2 != 0 and odd > eve:
		print('-1')
	else:
		(e, o) = (0, 0)
		for i in range(n):
			if a[i] % 2 != i % 2:
				if a[i] % 2 == 0:
					e += 1
				else:
					o += 1
		if e == o:
			print(e)
		else:
			print('-1')


T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	count1 = count2 = 0
	for i in range(n):
		if i % 2 != 0 and A[i] % 2 == 0:
			count1 += 1
		elif i % 2 == 0 and A[i] % 2 != 0:
			count2 += 1
	if count1 == count2:
		print(count1)
	else:
		print('-1')


n = int(input())
for i in range(n):
	k = int(input())
	a = list(map(int, input().split()))
	x = 0
	y = 0
	for j in range(k):
		if j % 2 != a[j] % 2:
			if j % 2 == 0:
				x += 1
			else:
				y += 1
	r = -1
	if x == y:
		r = x
	print(r)


import math
t = int(input())
for i in range(t):
	n = int(input())
	data = list(map(int, input().split()))
	wrong_odd = 0
	wrong_even = 0
	for j in range(len(data)):
		if j % 2 == 0:
			if data[j] % 2 == 1:
				wrong_even = wrong_even + 1
		elif data[j] % 2 == 0:
			wrong_odd = wrong_odd + 1
	if wrong_even != wrong_odd:
		print(-1)
	else:
		print(int(wrong_even))


for _ in range(int(input())):
	N = int(input())
	G = list(map(int, input().split()))
	TM = []
	GM = []
	M = []
	for i in range(N):
		TM.append(i % 2)
	for i in range(N):
		GM.append(G[i] % 2)
	for i in range(N):
		if i % 2 != G[i] % 2:
			M.append(G[i] % 2)
	if len(M) == 0:
		print(0)
	elif M.count(0) == M.count(1):
		print((M.count(0) + M.count(1)) // 2)
	else:
		print(-1)


def solve(li):
	count = 0
	i = 0
	even = 0
	odd = 0
	while i < len(li):
		if li[i] % 2 != i % 2:
			count += 1
			if li[i] % 2 == 0:
				even += 1
			else:
				odd += 1
		i += 1
	if count % 2 == 0 and even == odd:
		return count // 2
	else:
		return -1
t = int(input())
for i in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	print(solve(li))


from math import radians
from heapq import heapify, heappush, heappop
import bisect
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li1():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p] == True:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1
	return isPrime

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def treeOrderByDepth(n, adj, root=0):
	parent = [-2] + [-1] * (n - 1)
	ordered = []
	q = deque()
	q.append(root)
	depth = [0] * n
	while q:
		c = q.popleft()
		ordered.append(c)
		for a in adj[c]:
			if parent[a] == -1:
				parent[a] = c
				depth[a] = depth[c] + 1
				q.append(a)
	return (ordered, parent, depth)

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def nextPowerOf2(n):
	count = 0
	if n and (not n & n - 1):
		return n
	while n != 0:
		n >>= 1
		count += 1
	return 1 << count
for _ in range(ii()):
	n = ii()
	l = li1()
	par = []
	(e, o) = (0, 0)
	c = 0
	j = 0
	for i in l:
		if i % 2 == 0:
			e += 1
			par.append(j)
		j += 1
	if n % 2 == 0 and e != n // 2:
		print(-1)
	elif n % 2 != 0 and e != n // 2 + 1:
		print(-1)
	else:
		for i in par:
			if i % 2 != 0:
				c += 1
		print(c)


t = int(input())
for i in range(t):
	sm = int(input())
	inn = input().split()
	js = 0
	os = 0
	ans = 0
	for (it, a) in enumerate(inn):
		a = int(a)
		if a % 2 == 0:
			os += 1
			if it % 2 != 0:
				ans += 1
		else:
			js += 1
			if it % 2 != 1:
				ans += 1
	if sm % 2 == 0:
		if js != os:
			print('-1')
			continue
	elif js + 1 != os:
		print('-1')
		continue
	print(ans // 2)


for _ in range(int(input())):
	n = input()
	x = y = 0
	for (i, a) in enumerate(map(int, input().split())):
		if i % 2:
			x += 1 - a % 2
		else:
			y += a % 2
	print(x if x == y else -1)


n = int(input())
for i in range(n):
	a = int(input())
	b = list(map(int, input().split(' ')))
	c = 0
	d = 0
	for i in range(a):
		if i % 2 != b[i] % 2 and i % 2 == 0:
			d += 1
		elif i % 2 != b[i] % 2 and i % 2 == 1:
			c += 1
	if c != d:
		print('-1')
	else:
		print(c)


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	od = 0
	ev = 0
	for i in range(len(a)):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				od = od + 1
		elif i % 2 != 0:
			if a[i] % 2 == 0:
				ev = ev + 1
	if od == ev:
		print(od)
	else:
		print('-1')
	t = t - 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	wrong = [0, 0]
	for (i, k) in enumerate(a):
		if k % 2 != i % 2:
			wrong[i % 2] += 1
	if wrong[0] != wrong[1]:
		print(-1)
	else:
		print(wrong[0])


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	oi = 0
	ei = 0
	for i in range(n):
		if (arr[i] - i) % 2 != 0:
			if i % 2 == 0:
				oi += 1
			else:
				ei += 1
	if oi == ei:
		print(oi)
	else:
		print(-1)


t = int(input())
arr_list = []
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr_list.append(arr)
for arr in arr_list:
	good = 0
	even = 0
	odd = 0
	for i in range(len(arr)):
		if arr[i] % 2 == 0:
			if i % 2 == 0:
				good += 1
			else:
				odd += 1
		elif i % 2 == 0:
			even += 1
		else:
			good += 1
	if good == len(arr):
		print(0)
	elif even == odd:
		print(even)
	else:
		print(-1)


import sys
read = lambda : sys.stdin.readline()
T = int(read())
for t in range(T):
	n = int(read())
	arr = list(map(int, input().split()))
	eono = 0
	oone = 0
	for i in range(n):
		if arr[i] % 2 == 0 and i % 2 == 1:
			eono += 1
		if arr[i] % 2 == 1 and i % 2 == 0:
			oone += 1
	if eono == oone:
		print(eono)
	else:
		print(-1)


def bad(l):
	bad_odds = 0
	bad_evens = 0
	for i in range(len(l)):
		if i % 2 != l[i] % 2:
			if i % 2 == 0:
				bad_evens += 1
			else:
				bad_odds += 1
	if bad_evens != bad_odds:
		return -1
	else:
		return bad_evens
t = int(input())
for _ in range(t):
	_ = int(input())
	l = list(map(int, input().split()))
	sol = bad(l)
	print(sol)


t = int(input())
for _ in range(t):
	n = int(input())
	(ans, p) = (0, 0)
	arr = list(map(int, input().split()))
	for i in range(n):
		if i % 2 != 0 and arr[i] % 2 == 0:
			ans += 1
		if arr[i] % 2 != 0:
			p += 1
	if p == n // 2:
		print(ans)
	else:
		print(-1)


t = int(input())
for k in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	c1 = 0
	c2 = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			c1 += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			c2 += 1
	if c1 == c2:
		print((c1 + c2) // 2)
	else:
		print(-1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(e, o) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			e += 1
		if i % 2 == 1 and a[i] % 2 == 0:
			o += 1
	if o != e:
		print(-1)
	else:
		print((o + e) // 2)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		ar = inpt()
		ct = 0
		ev = 0
		od = 0
		c = 0
		for i in range(n):
			if i % 2 != ar[i] % 2:
				if i % 2 == 1:
					ct += 1
				else:
					ct -= 1
				c += 1
		if ct != 0:
			print(-1)
		else:
			print(c // 2)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s1 = 0
	s2 = 0
	for j in range(len(l)):
		if j % 2 != l[j] % 2:
			if j % 2 == 0:
				s1 += 1
			else:
				s2 += 1
	if s1 != s2:
		print(-1)
	else:
		print(s1)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
N = 5 * 10 ** 5 + 7
for _ in range(I()):
	n = I()
	a = L()
	e = o = 0
	for i in a:
		if i % 2:
			o += 1
		else:
			e += 1
	if o + n % 2 != e:
		print(-1)
	else:
		cnt = 0
		for i in range(n):
			if i % 2 != a[i] % 2:
				cnt += 1
		print(cnt // 2)


t = int(input())
for i in range(t):
	ans = -1
	n = int(input())
	s = list(map(int, input().split()))
	cnt0 = 0
	cnt1 = 0
	for j in range(n):
		if j % 2 == 0 and s[j] % 2 != 0:
			cnt0 += 1
		if j % 2 != 0 and s[j] % 2 == 0:
			cnt1 += 1
	if cnt0 == cnt1:
		ans = cnt0
	print(ans)


for k in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(z, o) = (0, 0)
	for i in range(n):
		if i % 2 != l[i] % 2:
			if l[i] % 2 == 0:
				z += 1
			else:
				o += 1
	if o != z:
		print(-1)
	else:
		print(o)


n = int(input())
all_ans = []
for _ in range(n):
	length = int(input())
	nums = list(map(eval, input().split()))
	even_idx = 0
	odd_idx = 0
	for i in range(0, length, 2):
		if nums[i] % 2 != 0:
			even_idx += 1
	for i in range(1, length, 2):
		if nums[i] % 2 == 0:
			odd_idx += 1
	if even_idx == odd_idx:
		all_ans.append(str(even_idx))
	else:
		all_ans.append('-1')
print('\n'.join(all_ans))


t = int(input())
for i in range(t):
	n = int(input())
	nn = [int(s) for s in input().split()]
	s = 0
	ss = 0
	for j in range(n):
		if nn[j] % 2 == 0:
			s += 1
			if j % 2 == 0:
				ss += 1
	if s == n % 2 + n // 2:
		print(s - ss)
	else:
		print(-1)


import math
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	e = 0
	o = 0
	be = 0
	bo = 0
	for i in range(n):
		if a[i] % 2 == 0:
			e += 1
			if i % 2 == 1:
				be += 1
		else:
			o += 1
			if i % 2 == 0:
				bo += 1
	if math.ceil(n / 2) == e and n // 2 == o:
		print((be + bo) // 2)
	else:
		print(-1)


t = int(input())
for x in range(t):
	n = int(input())
	arr = map(int, input().split(' '))
	(misplaced_even, misplaced_odd) = (0, 0)
	for (i, a) in enumerate(arr):
		(k, l) = (i % 2, a % 2)
		if k != l:
			if l == 0:
				misplaced_even += 1
			else:
				misplaced_odd += 1
	if misplaced_even != misplaced_odd:
		print(-1)
	else:
		print(misplaced_even)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(q, w1) = (0, 0)
	w = []
	h = []
	p = {}
	f = {}
	p[0] = 0
	p[1] = 0
	f[0] = 0
	f[1] = 0
	ans = 0
	b = -1
	for i in a:
		h.append(i % 2)
	for i in range(n):
		w.append(i % 2)
	if w == h:
		print(0)
		b = 0
	else:
		for i in range(0, n):
			for j in range(i + 1, n):
				if h[i] != w[i]:
					x = 1 - h[i]
					if x == h[j] and h[j] != w[j]:
						q = h[i]
						h[i] = h[j]
						h[j] = q
						ans += 1
						break
		if h == w:
			print(ans)
		else:
			print(-1)


for _ in range(int(input())):
	d = {'even': 0, 'odd': 0}
	input()
	lst = [int(x) for x in input().split(' ')]
	for i in range(len(lst)):
		if i % 2 != lst[i] % 2:
			if lst[i] % 2 == 0:
				d['even'] += 1
			else:
				d['odd'] += 1
	if d['even'] == d['odd']:
		print(d['odd'])
	else:
		print(-1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	ar = [int(i) for i in input().strip().split()]
	even = odd = 0
	for i in range(n):
		if i % 2 != ar[i] % 2:
			if ar[i] % 2 == 0:
				even += 1
			else:
				odd += 1
	if even != odd:
		print(-1)
	else:
		print(even)


t = int(input())
for z in range(t):
	oddInEvenEl = 0
	evenInOddEl = 0
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 == 1:
			evenInOddEl += 1
		elif i % 2 == 1 and arr[i] % 2 == 0:
			oddInEvenEl += 1
	if oddInEvenEl != evenInOddEl:
		print(-1)
	else:
		print(oddInEvenEl)


def evenArr(arr, n):
	(o, e) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			if arr[i] % 2 == 1:
				e += 1
		elif arr[i] % 2 == 0:
			o += 1
	if o == e:
		return o
	return -1
t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	print(evenArr(arr, n))
	t -= 1


def main():
	t = int(input())
	sizes = []
	arrays = []
	for case in range(t):
		sizes.append(int(input()))
		arrays.append(input().split())
	case = 0
	while case < t:
		size = sizes[case]
		ar = arrays[case]
		stack1 = []
		stack2 = []
		count = 0
		for i in range(size):
			if int(ar[i]) % 2 == 0 and i % 2 == 1:
				stack1.append(i)
			elif int(ar[i]) % 2 == 1 and i % 2 == 0:
				stack2.append(i)
		i = 0
		while i < size:
			if i % 2 == int(ar[i]) % 2:
				i += 1
				while len(stack1) > 0 and i >= stack1[0]:
					stack1.pop(0)
				while len(stack2) > 0 and i >= stack2[0]:
					stack2.pop(0)
			else:
				if len(stack1) > 0 and i % 2 == 0:
					index = stack1.pop(0)
				elif len(stack2) > 0 and i % 2 == 1:
					index = stack2.pop(0)
				else:
					count = -1
					break
				temp = ar[index]
				ar[index] = ar[i]
				ar[i] = temp
				count += 1
				i += 1
		case += 1
		print(count)
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	e = 0
	o = 0
	for el in range(n):
		if a[el] % 2 == 0:
			e += 1
		else:
			o += 1
	if n % 2 == 0:
		if e != o:
			print(-1)
			continue
	elif e != o + 1:
		print(-1)
		continue
	min = 0
	for el in range(n):
		if a[el] % 2 != el % 2:
			min += 1
	print(min // 2)


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	even = 0
	for (i, x) in enumerate(a):
		if i % 2 == 1 and x % 2 == 0:
			odd += 1
		elif i % 2 == 0 and x % 2 == 1:
			even += 1
	if odd == even:
		ans = odd
	else:
		ans = -1
	print(ans)


t = int(input())
for i in range(t):
	o = 0
	e = 0
	c = 0
	length = int(input())
	l = list(map(int, input().split()))
	if len(l) == 1:
		if l[0] % 2 != 0:
			print('-1')
			continue
	for x in l:
		if x % 2 == 0:
			e += 1
		else:
			o += 1
	if len(l) % 2 == 0 and e != o:
		print('-1')
		continue
	if len(l) % 2 != 0 and e != o + 1:
		print('-1')
		continue
	for ind in range(0, len(l)):
		if ind % 2 == 0 and l[ind] % 2 != 0:
			c += 1
		elif ind % 2 != 0 and l[ind] % 2 == 0:
			c += 1
	print(c // 2)


for _ in range(int(input())):
	x = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in range(x):
		if a[i] % 2 != i % 2 and i % 2 == 1:
			b.append(1)
		elif a[i] % 2 != i % 2 and i % 2 == 0:
			b.append(0)
	if b.count(0) == b.count(1):
		print(b.count(0))
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	e = 0
	d = 0
	a = list(map(int, input().split()))
	even = [(j, v) for (j, v) in enumerate(a) if v % 2 == 0]
	odd = [(j, v) for (j, v) in enumerate(a) if v % 2 != 0]
	if len(even) != n // 2 + n % 2 or len(odd) != n // 2:
		print('-1')
	else:
		for (j, v) in even:
			if j % 2 != v % 2:
				e += 1
		for (j, v) in odd:
			if j % 2 != v % 2:
				d += 1
		if e == d:
			print(e)


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	counte = 0
	counto = 0
	for i in range(len(l)):
		if i % 2 != l[i] % 2:
			if l[i] % 2 == 0:
				counte += 1
			else:
				counto += 1
	if counte == counto:
		print(counte)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	j = 0
	no = 0
	ne = 0
	for i in lst:
		if j % 2 == 0 and i % 2 != 0:
			ne += 1
		elif j % 2 != 0 and i % 2 == 0:
			no += 1
		j += 1
	if ne == no:
		print(ne)
	else:
		print(-1)


def countMinSwaps(st):
	min_swaps = 0
	(odd_0, even_0) = (0, 0)
	(odd_1, even_1) = (0, 0)
	n = len(st)
	for i in range(0, n):
		if i % 2 == 0:
			if st[i] == '1':
				even_1 += 1
			else:
				even_0 += 1
		elif st[i] == '1':
			odd_1 += 1
		else:
			odd_0 += 1
	if odd_0 + even_0 != even_1 + even_0:
		return -1
	else:
		cnt_swaps_1 = min(even_0, odd_1)
		cnt_swaps_2 = min(even_1, odd_0)
		return cnt_swaps_2
test = int(input())
for i in range(test):
	n = int(input())
	arr = [int(x) for x in input().split()]
	bin2 = [0] * n
	for i in range(n):
		bin2[i] = arr[i] % 2
	ans = ''.join(map(str, bin2))
	print(countMinSwaps(ans))


def sol(arr):
	max_swaps = len(arr)
	even_count = len(list(filter(lambda x: x % 2 == 0, arr)))
	odd_count = len(list(filter(lambda x: x % 2 != 0, arr)))
	if max_swaps % 2 == 0 and even_count != odd_count:
		return -1
	elif max_swaps % 2 != 0 and even_count != odd_count + 1:
		return -1
	j = 0
	swaps = 0
	while j < len(arr) and swaps <= max_swaps:
		if arr[j] % 2 == 0 and j % 2 != 0:
			swaps += 1
		elif arr[j] % 2 != 0 and j % 2 == 0:
			swaps += 1
		j += 1
	if j == len(arr):
		return swaps // 2
	else:
		return -1
n = int(input())
for i in range(n):
	k = int(input())
	arr = list(map(int, input().split()))
	print(sol(arr))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(e, o) = (0, 0)
	for i in range(n):
		if a[i] % 2 != 0:
			o += 1
	if n % 2 == 0:
		ch = int(n / 2)
	else:
		ch = int((n - 1) / 2)
	if o != ch:
		print(-1)
	else:
		cnt = 0
		for i in range(0, n, 2):
			if a[i] % 2 != 0:
				cnt += 1
		print(cnt)


t = int(input())
for _ in range(t):
	n = int(input())
	(even, odd) = (0, 0)
	arr = [int(var) for var in input().split()]
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if arr[i] % 2 == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
i = 0
while i < t:
	n = int(input())
	a = list(map(int, input().split()))
	j = 0
	case = 0
	c = []
	while j < n:
		if a[j] % 2 != j % 2:
			case += 1
			c.append(a[j] % 2)
		j += 1
	c.sort()
	if c.count(0) != c.count(1):
		case = -1
	print(case // 2)
	i += 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ceve = 0
	codd = 0
	ce = 0
	co = 0
	for j in range(len(a)):
		if a[j] % 2 == 0:
			ceve += 1
		else:
			codd += 1
	for z in range(len(a)):
		if z % 2 == 0 and a[z] % 2 != 0:
			ce += 1
		elif z % 2 != 0 and a[z] % 2 == 0:
			co += 1
	if ce != co:
		print(-1)
	else:
		print((ce + co) // 2)


for _ in range(int(input())):
	q = int(input())
	a = list(map(int, input().split()))
	x = []
	q = 0
	q1 = 0
	q2 = 0
	for i in range(len(a)):
		if i % 2 == a[i] % 2:
			q += 1
		elif i % 2 == 0:
			q1 += 1
		else:
			q2 += 1
	if q1 == q2:
		print(q1)
	else:
		print(-1)


c = []
for i in range(int(input())):
	x = int(input())
	a = list(map(int, input().split()))
	e = 0
	o = 0
	d = 0
	for j in range(len(a)):
		if a[j] % 2 == 0:
			e += 1
		else:
			o += 1
		if a[j] % 2 == 0 and j % 2 != 0 or (a[j] % 2 != 0 and j % 2 == 0):
			d += 1
	if len(a) % 2 == 0:
		if e != o:
			c.append(-1)
		else:
			c.append(d // 2)
	elif o + 1 != e:
		c.append(-1)
	else:
		c.append(d // 2)
for i in c:
	print(i)


n = int(input())
for i in range(n):
	m = int(input())
	odd = 0
	even = 0
	a = list(map(int, input().strip().split()))[:m]
	for j in range(m):
		if a[j] % 2 == 0:
			even = even + 1
		else:
			odd = odd + 1
	if odd == m // 2 and even == m // 2 + m % 2:
		d = 0
		for i in range(m):
			if a[i] % 2 != i % 2:
				d = d + 1
		print(d // 2)
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	nums = list(map(int, input().split()))
	eo = 0
	oe = 0
	i = 0
	while i < len(nums):
		if i % 2 != nums[i] % 2:
			if i % 2 == 0:
				eo += 1
			else:
				oe += 1
		i = i + 1
	if eo == oe:
		print(eo)
	else:
		print(-1)
	t = t - 1


for _ in range(int(input())):
	k = int(input())
	l = list(map(int, input().split()))
	o = 0
	e = 0
	q = 0
	for i in range(k):
		if l[i] % 2 != i % 2:
			q += 1
		if l[i] % 2 == 1:
			o += 1
		else:
			e += 1
	if o == k // 2 and e == k // 2 + k % 2:
		print(q // 2)
	else:
		print(-1)


t = int(input())
for j in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	c = 0
	b = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if (i + 1) % 2 == 0:
				c += 1
			else:
				b += 1
	if c == b:
		print(c)
	else:
		print(-1)


from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
sqrt = math.sqrt

def LI():
	return list(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def LI_():
	return list(map(lambda x: int(x) - 1, input().split()))

def II():
	return int(input())

def IF():
	return float(input())

def S():
	return input().rstrip()

def LS():
	return S().split()

def IR(n):
	res = [None] * n
	for i in range(n):
		res[i] = II()
	return res

def LIR(n):
	res = [None] * n
	for i in range(n):
		res[i] = LI()
	return res

def FR(n):
	res = [None] * n
	for i in range(n):
		res[i] = IF()
	return res

def LIR(n):
	res = [None] * n
	for i in range(n):
		res[i] = IF()
	return res

def LIR_(n):
	res = [None] * n
	for i in range(n):
		res[i] = LI_()
	return res

def SR(n):
	res = [None] * n
	for i in range(n):
		res[i] = S()
	return res

def LSR(n):
	res = [None] * n
	for i in range(n):
		res[i] = LS()
	return res
mod = 1000000007
inf = float('INF')

def solve():
	for _ in range(II()):
		n = II()
		a = LI()
		odd = 0
		even = 0
		for i in range(n):
			if i & 1 != a[i] & 1:
				if i & 1:
					even += 1
				else:
					odd += 1
		if even == odd:
			print(even)
		else:
			print(-1)
	return
solve()


import math
import sys
import itertools

def sa(Type=int):
	return [Type(x) for x in input().split()]

def solve(t):
	n = input()
	arr = sa()
	oddInEven = 0
	evenInOdd = 0
	for (idx, x) in enumerate(arr):
		xOdd = x % 2 == 1
		iOdd = idx % 2 == 1
		if xOdd and (not iOdd):
			oddInEven += 1
		elif not xOdd and iOdd:
			evenInOdd += 1
	ans = None
	if oddInEven == evenInOdd:
		ans = oddInEven
	else:
		ans = -1
	print(ans)
t = int(input())
for i in range(t):
	solve(i + 1)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split(' ')))
	idne = 0
	ieno = 0
	for i in range(len(arr)):
		if i % 2 != 0 and arr[i] % 2 == 0:
			idne += 1
		if i % 2 == 0 and arr[i] % 2 != 0:
			ieno += 1
	if idne == ieno:
		print(idne)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	even = {False: 0, True: 0}
	nums = map(int, input().split())
	for (i, v) in enumerate(nums):
		even[i % 2 == 0] += int(i % 2 != v % 2)
	print(even[True] if even[True] == even[False] else -1)


n = int(input())
for i in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	count = 0
	k = []
	h = []
	for j in range(len(l)):
		h.append(l[j] % 2)
		k.append(j % 2)
		if j % 2 != l[j] % 2:
			count += 1
	if k.count(0) != h.count(0) or k.count(1) != h.count(1):
		print(-1)
	else:
		print(count // 2)


for _ in range(int(input())):
	cnt1 = 0
	cnt2 = 0
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n):
		if i % 2 != l[i] % 2 and i % 2:
			cnt1 += 1
		if i % 2 != l[i] % 2 and (not i % 2):
			cnt2 += 1
	print(cnt1 if cnt2 == cnt1 else -1)


N = int(input())
count = 0
for i in range(N):
	count = 0
	countodd = 0
	nn = int(input())
	oldnum = input()
	num = oldnum.split()
	for j in range(nn):
		if int(num[j]) % 2 != j % 2:
			count += 1
		if int(num[j]) % 2 != 0:
			countodd += 1
	if countodd != int(nn / 2):
		print(-1)
	else:
		print(int(count / 2))


testcase = int(input())
for i in range(testcase):
	n = int(input())
	li = list(map(int, input().split()))
	count_even = 0
	count_odd = 0
	for j in range(n):
		if j % 2 != 0 and li[j] % 2 == 0:
			count_even += 1
		elif j % 2 == 0 and li[j] % 2 != 0:
			count_odd += 1
	if count_even == count_odd:
		print(count_even)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	evenwrong = 0
	oddwrong = 0
	for j in range(n):
		if arr[j] % 2 == 0 and j % 2 != 0:
			evenwrong += 1
		elif arr[j] % 2 != 0 and j % 2 == 0:
			oddwrong += 1
	if evenwrong == oddwrong:
		print(int(evenwrong))
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	nc = 0
	for p in range(n):
		if p % 2 == 0 and a[p] % 2 != 0:
			c += 1
		elif p % 2 != 0 and a[p] % 2 == 0:
			nc += 1
	if c == nc:
		print(c)
	else:
		print(-1)


def f(arr):
	a = 0
	b = 0
	for i in range(len(arr)):
		if i % 2 != arr[i] % 2:
			a += int(arr[i] % 2 == 0)
			b += int(arr[i] % 2 == 1)
	if a != b:
		print(-1)
	else:
		print(a)
t = int(input())
for i in range(t):
	input()
	arr = [int(a) for a in input().split(' ')]
	f(arr)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(ec, oc) = (0, 0)
	f = True
	for i in range(n):
		if a[i] & 1:
			oc += 1
		else:
			ec += 1
	if n & 1:
		if oc != n // 2 or ec != n // 2 + 1:
			f = False
	elif oc != n // 2 or ec != n // 2:
		f = False
	cnt = 0
	if f == True:
		for i in range(n):
			if i % 2 == 0 and a[i] % 2 == 1 or (i % 2 == 1 and a[i] % 2 == 0):
				cnt += 1
		print(cnt // 2)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n1 = 0
	n2 = 0
	n = int(input())
	a = [int(i) for i in input().split()]
	for j in range(n):
		if j % 2 != a[j] % 2:
			if a[j] % 2 == 0:
				n1 += 1
			else:
				n2 += 1
	if n1 != n2:
		print(-1)
	else:
		print(n1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	one = 0
	two = 0
	for i in range(n):
		if a[i] % 2 == i % 2:
			continue
		elif a[i] % 2 == 0:
			two += 1
		else:
			one += 1
	if one == two:
		print(one)
	elif one != two:
		print(-1)
	else:
		print(0)


q = int(input())
while q > 0:
	g = input()
	nums = input().split(' ')
	(even, odd, c) = (0, 0, 0)
	nums = [int(_) for _ in nums]
	i = 0
	for num in nums:
		if num % 2 != i % 2:
			c += 1
			if num % 2 == 0:
				even += 1
			if num % 2 != 0:
				odd += 1
		i += 1
	if c % 2 == 0 and even == odd:
		print(int(c / 2))
	else:
		print(-1)
	q -= 1


from sys import stdin
import math
n = int(stdin.readline().rstrip())
for _ in range(n):
	stdin.readline()
	arr = list(map(int, stdin.readline().rstrip().split(' ')))
	bad_evens = 0
	bad_odds = 0
	for (i, num) in enumerate(arr):
		if num % 2 == 0 and i % 2 == 1:
			bad_evens += 1
		elif num % 2 == 1 and i % 2 == 0:
			bad_odds += 1
	if bad_evens == bad_odds:
		print(bad_evens)
	else:
		print(-1)


t = int(input())
for i in range(t):
	count1 = 0
	count2 = 0
	n = int(input())
	a = list(map(int, input().split()))
	for k in range(len(a)):
		if k % 2 != a[k] % 2:
			if a[k] % 2 == 1:
				count2 += 1
			else:
				count1 += 1
	if count1 != count2:
		print(-1)
	else:
		print(count1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	even_wrong = 0
	odd_wrong = 0
	for i in range(0, n, 2):
		if a[i] % 2 == 1:
			even_wrong += 1
	for i in range(1, n, 2):
		if a[i] % 2 == 0:
			odd_wrong += 1
	print(even_wrong if even_wrong == odd_wrong else -1)


def sol(l):
	even = 0
	count = 0
	for _ in range(len(l)):
		if l[_] % 2 == 0:
			even += 1
	if len(l) % 2 == 0:
		ke = len(l) / 2
	else:
		ke = (len(l) + 1) / 2
	if even != ke:
		return -1
	else:
		for _ in range(len(l)):
			if l[_] % 2 != _ % 2:
				count += 1
		return count // 2
t = int(input())
for _ in range(t):
	z = input()
	l = [int(i) for i in input().split()]
	print(sol(l))


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()][:n]
	(swapodd, swapeven) = (0, 0)
	for i in range(len(arr)):
		if i % 2 == 0 and arr[i] % 2 != 0:
			swapodd += 1
		if i % 2 != 0 and arr[i] % 2 == 0:
			swapeven += 1
	if swapodd == swapeven:
		print(swapodd)
	else:
		print(-1)


def even_arr(arr, n):
	even_counter = odd_counter = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			even_counter += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			odd_counter += 1
	if even_counter != odd_counter:
		return -1
	else:
		return even_counter
t = int(input())
for t_itr in range(t):
	n = int(input())
	arr = list(map(int, input().rstrip().split()))
	result = even_arr(arr, n)
	print(result)


def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split(' ')))
t = read_int()
for case_num in range(t):
	n = read_int()
	a = list(read_ints())
	o2e = 0
	e2o = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			o2e += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			e2o += 1
	print(-1 if o2e != e2o else o2e)


for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	odd = []
	even = []
	for j in range(n):
		if a[j] % 2 == 0:
			if j % 2 == 0:
				continue
			else:
				odd.append(j)
		elif j % 2 == 0:
			even.append(j)
		else:
			continue
	if len(odd) == len(even):
		print(len(odd))
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = x = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			c += 1
		if l[i] % 2 != 0:
			x += 1
	if c % 2 == 0 and n // 2 == x:
		print(c // 2)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	subcount = 0
	for j in range(0, n):
		if j % 2 != 0:
			if arr[j] % 2 == 0:
				count = count + 1
		elif arr[j] % 2 != 0:
			subcount = subcount + 1
	if count == subcount:
		print((count + subcount) // 2)
	else:
		print('-1')


import math
from decimal import *
getcontext().prec = 30
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	(e, o) = (0, 0)
	for val in a:
		if val % 2 == 0:
			e += 1
		else:
			o += 1
	if e != (n + 1) // 2:
		print(-1)
		continue
	c = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			c += 1
	print(c // 2)


for ii in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	(o, e) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and p[i] % 2 != 0:
			e += 1
		elif i % 2 != 0 and p[i] % 2 == 0:
			o += 1
	if e == 0 and o == 0:
		print(0)
	elif e == o:
		print(e)
	else:
		print(-1)


T = int(input())
for t in range(T):
	n = int(input())
	arr = [int(x) for x in input().split()]
	c1 = 0
	c2 = 0
	for i in range(0, n, 2):
		if arr[i] % 2 == 1:
			c1 += 1
	for j in range(1, n, 2):
		if arr[j] % 2 == 0:
			c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)


n = int(input())
for x in range(n):
	a = int(input())
	b = []
	p = True
	o = e = i = 0
	oddnotgood = 0
	evennotgood = 0
	for x in input().split():
		x = int(x)
		if i % 2 == 0 and x % 2 == 1:
			oddnotgood += 1
		elif i % 2 == 1 and x % 2 == 0:
			evennotgood += 1
		i += 1
	if oddnotgood == evennotgood:
		print(oddnotgood)
	else:
		print(-1)


t = int(input())
for i in range(0, t):
	n = int(input())
	a = input().split()
	(ev, od) = (0, 0)
	(evp, odp) = (0, 0)
	for j in range(0, n):
		a[j] = int(a[j])
		ev = ev + 1 if a[j] % 2 == 0 else ev
		od = od + 1 if a[j] % 2 else od
		evp = evp + 1 if a[j] % 2 == 0 and j % 2 == 0 else evp
		odp = odp + 1 if a[j] % 2 and j % 2 else odp
	if ev != od and ev - 1 != od:
		print(-1)
	else:
		print(ev - evp)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	even = 0
	bad_odd = 0
	bad_even = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 0:
				bad_even += 1
			else:
				bad_odd += 1
		if a[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	if odd < n // 2:
		print(-1)
	elif n % 2 == 0 and even < n // 2:
		print(-1)
	elif n % 2 != 0 and even < n // 2 + 1:
		print(-1)
	else:
		print(max(bad_odd, bad_even))


t = int(input())
for i in range(t):
	a = 0
	b = 0
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n):
		if arr[i] % 2 != i % 2:
			if i % 2 == 0:
				a += 1
			else:
				b += 1
	if a != b:
		print(-1)
	else:
		print(b)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(c1, c2) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			c1 += 1
		if i % 2 == 1 and a[i] % 2 != 1:
			c2 += 1
	if c1 != c2:
		print(-1)
	else:
		print(c1)


def even(l, n):
	(ec, oc) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 != 0:
			ec += 1
		elif i % 2 == 1 and l[i] % 2 != 1:
			oc += 1
	if ec == oc:
		return ec
	else:
		return -1
t = int(input())
for case in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(even(l, n))


z = input
import math
n = int(input())
p = []
for i in range(n):
	x = int(input())
	l = list(map(int, input().split()))
	c = 0
	p = []
	u = 0
	for i in range(x):
		if l[i] % 2 != i % 2:
			c += 1
			g = l[i] % 2
			p.append(g)
	if c == 0:
		print(c)
		continue
	o = p.count(1)
	z = p.count(0)
	if o == z:
		print(o)
		continue
	print(-1)


testcases = int(input())
while testcases > 0:
	testcases = testcases - 1
	length = int(input())
	array = list(map(int, input().split()))
	(odd, even) = (0, 0)
	for i in range(0, length):
		if array[i] % 2 != i % 2:
			if array[i] % 2 == 0 and i % 2 == 1:
				odd = odd + 1
			else:
				even = even + 1
	if odd == even:
		print(odd)
	else:
		print('-1')


test = int(input())
for _ in range(test):
	n = int(input())
	arr = list(map(int, input().split()))
	bo = []
	be = []
	for i in range(len(arr)):
		if arr[i] % 2 and i % 2 == 0:
			bo.append(i)
		elif arr[i] % 2 == 0 and i % 2:
			be.append(i)
	if len(bo) == len(be):
		print(len(bo))
	else:
		print(-1)


import math
import os
import random
import re
import sys
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	w1 = 0
	w2 = 0
	for i in range(n):
		if arr[i] % 2 != i % 2:
			if i % 2 == 1:
				w1 += 1
			else:
				w2 += 1
	if w1 != w2:
		print(-1)
	else:
		print(w1)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0:
			if arr[i] % 2 == 0:
				continue
			else:
				odd += 1
		elif arr[i] % 2 != 0:
			continue
		else:
			even += 1
	if even == odd:
		print(even)
	else:
		print(-1)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(n):
		if l[i] % 2 != i % 2:
			if l[i] % 2 == 1:
				odd += 1
			else:
				even += 1
	if odd == even:
		print(odd)
	else:
		print(-1)
	t -= 1


from sys import stdin
input = lambda : stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd, log
for _ in rn():
	n = INT()
	l = mp()
	(co, ce) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			if l[i] % 2 == 1:
				co += 1
		elif l[i] % 2 == 0:
			ce += 1
	if co == ce:
		print(co)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	od = ev = 0
	flag = 0
	for i in l:
		if flag == 0:
			if i % 2 == 0:
				flag = 1
				continue
			else:
				od += 1
				flag = 1
		elif i % 2 != 0:
			flag = 0
			continue
		else:
			ev += 1
			flag = 0
	if ev != od:
		print('-1')
	else:
		print(od)


for _ in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))
	i = 0
	j = 0
	k = 1
	l = 0
	while i < n:
		if int(num[i]) % 2 != 0:
			j += 1
			i += 2
		else:
			j += 0
			i += 2
	while k < n:
		if int(num[k]) % 2 == 0:
			l += 1
			k += 2
		else:
			l += 0
			k += 2
	if j == l:
		print((j + l) // 2)
	else:
		print('-1')


def solve():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		(e, o) = (0, 0)
		for (i, j) in enumerate(a):
			if i % 2 != j % 2:
				if j % 2 == 1:
					o += 1
				else:
					e += 1
		print(e if e == o else -1)
solve()


for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	c = 0
	co = 0
	ce = 0
	for i in range(n):
		if i % 2 == 0:
			if list1[i] % 2 != 0:
				co += 1
		elif list1[i] % 2 == 0:
			ce += 1
	if co == ce:
		print(co)
	else:
		print(-1)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		ar = list(map(int, input().split()))
		c1 = 0
		c2 = 0
		for i in range(n):
			if ar[i] % 2 == 0 and i % 2 != 0:
				c1 += 1
			if ar[i] % 2 == 1 and i % 2 != 1:
				c2 += 1
		print((c1, -1)[c1 != c2])
main()


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	ev = 0
	od = 0
	k = 0
	for i in lis:
		if i % 2 == 0:
			if k % 2 != 0:
				ev += 1
		elif k % 2 == 0:
			od += 1
		k += 1
	if od == ev:
		print(od)
	else:
		print(-1)


t = int(input())
while t:
	t -= 1
	d = int(input())
	l = list(map(int, input().split()))
	cnt_0 = 0
	cnt_1 = 0
	i = 0
	while i < d:
		if i % 2 != l[i] % 2:
			if i % 2 == 1:
				cnt_1 += 1
			if i % 2 == 0:
				cnt_0 += 1
		i += 1
	if cnt_0 == cnt_1:
		print(cnt_0)
	else:
		print(-1)


import sys
input = sys.stdin.readline

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()

def lower_letters():
	lowercase = [chr(i) for i in range(97, 97 + 26)]
	return lowercase

def upper_letters():
	uppercase = [chr(i) for i in range(65, 65 + 26)]
	return uppercase
for _ in range(int(input())):
	n = int(input())
	arr = int_array()
	(evens, odds) = (0, 0)
	for i in range(n):
		if arr[i] % 2 == 1 and i % 2 == 0:
			odds += 1
		elif arr[i] % 2 == 0 and i % 2 == 1:
			evens += 1
	if evens == odds:
		print(evens)
	else:
		print(-1)


for _ in range(int(input())):
	lens = int(input())
	arrs = [int(x) for x in input().split()]
	eves = 0
	odds = 0
	for (i, v) in enumerate(arrs):
		if v % 2 != i % 2:
			if i % 2 == 0:
				eves += 1
			else:
				odds += 1
	print(-1 if eves != odds else eves)


test_cases = int(input())
for i in range(test_cases):
	length = int(input())
	arr = [int(x) for x in input().split(' ')]
	(odds, evens) = (0, 0)
	for num in arr:
		if num % 2 == 1:
			odds += 1
		else:
			evens += 1
	if evens - odds > 1 or odds > evens:
		print(-1)
	elif evens - odds == 1 and len(arr) % 2 != 1:
		print(-1)
	else:
		bad_numbers = 0
		for number in range(len(arr)):
			if arr[number] % 2 != number % 2:
				bad_numbers += 1
		print(int(bad_numbers / 2))


for _ in range(int(input())):
	n = int(input())
	a = list(map(lambda x: int(x) % 2, input().split()))
	i = 1
	odd = 0
	even = 0
	for v in a:
		i = 1 - i
		if v == i:
			continue
		if v == 0:
			even += 1
		else:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	even = 0
	m = 0
	flag = True
	for (i, x) in enumerate(a):
		if i % 2 != x % 2:
			if x % 2 == 1:
				if even:
					even -= 1
					m += 1
				else:
					odd += 1
			if x % 2 == 0:
				if odd:
					odd -= 1
					m += 1
				else:
					even += 1
	if even == odd == 0:
		print(m)
	else:
		print(-1)


t = int(input())
while t:
	t -= 1
	length = int(input())
	a = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(length):
		if i % 2 == 1 and i % 2 != a[i] % 2:
			odd += 1
		elif i % 2 == 0 and i % 2 != a[i] % 2:
			even += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def diff(x, y):
	if x[1] - x[0] > y[1] - y[0]:
		return 1
	elif x[1] - x[0] == y[1] - y[0]:
		return x[0] < y[0]
	else:
		return 0

def main():
	t = inp()
	for l in range(t):
		n = inp()
		a = inlist()
		bad = 0
		odd = 0
		for i in range(n):
			if a[i] % 2 == 0:
				if i % 2 != 0:
					bad += 1
			else:
				odd += 1
				if i % 2 == 0:
					bad += 1
		if odd != n // 2:
			print('-1')
		else:
			print(bad // 2)
main()


for tc in range(int(input())):
	N = int(input())
	a = list(map(int, input().split()))
	tmp = [0, 0]
	for i in range(N):
		if i % 2:
			if not a[i] % 2:
				tmp[0] += 1
		elif a[i] % 2:
			tmp[1] += 1
	if tmp[0] == tmp[1]:
		print(tmp[0])
	else:
		print(-1)


for i in range(int(input())):
	N = int(input())
	a = list(map(int, input().split()))
	(cnt_even, cnt_odd) = (0, 0)
	for j in range(N):
		if a[j] % 2 != j % 2:
			if a[j] % 2 == 0:
				cnt_even += 1
			else:
				cnt_odd += 1
	if cnt_even != cnt_odd:
		cnt_even = -1
	print(cnt_even)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	t = int(input())
	while t != 0:
		n = int(input())
		arr = list(map(int, input().split()))[:n]
		flag = True
		even = 0
		odd = 0
		for i in range(n):
			if arr[i] % 2 == 0:
				if flag:
					flag = not flag
					continue
				else:
					flag = not flag
					even += 1
			elif not flag:
				flag = not flag
				continue
			else:
				flag = not flag
				odd += 1
		if even == odd:
			print(even)
		else:
			print(-1)
		t -= 1
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def check(li):
	length = len(li)
	(even, odd) = (0, 0)
	for num in li:
		if num % 2 == 0:
			even += 1
		else:
			odd += 1
	if length % 2 == 0:
		if even == length // 2 and odd == length // 2:
			return True
		else:
			return False
	elif odd == length // 2 and even == odd + 1:
		return True
	else:
		return False
t = int(input())
while t:
	n = int(input())
	li = [int(x) for x in input().split()]
	if check(li) == False:
		print(-1)
	else:
		count = 0
		for i in range(len(li)):
			if i % 2 == 0 and li[i] % 2 != 0:
				for j in range(i + 1, len(li)):
					if j % 2 != 0 and li[j] % 2 == 0:
						temp = li[i]
						li[i] = li[j]
						li[j] = temp
						count += 1
						break
			elif i % 2 != 0 and li[i] % 2 == 0:
				for j in range(i + 1, len(li)):
					if j % 2 == 0 and li[j] % 2 != 0:
						temp = li[i]
						li[i] = li[j]
						li[j] = temp
						count += 1
						break
		print(count)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = [int(x) % 2 for x in input().split()]
	ev = a.count(0)
	od = n - ev
	if n % 2 == 0 and ev != od or (n % 2 == 1 and ev != od + 1):
		print(-1)
	else:
		swaps = 0
		for i in range(n):
			if i % 2 != a[i]:
				swaps += 1
		print(swaps // 2)


t = int(input())
for tc in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	e = 0
	o = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			if i % 2 != arr[i] % 2:
				e += 1
		elif i % 2 != arr[i] % 2:
			o += 1
	if e == o:
		print(e)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ne = 0
	no = 0
	ei = n // 2
	oi = n // 2
	if n % 2 != 0:
		ei += 1
	for j in a:
		if j % 2 == 0:
			ne += 1
		else:
			no += 1
	if no == oi and ne == ei:
		c = 0
		for j in range(n):
			if j % 2 != a[j] % 2:
				c += 1
		print(c // 2)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				even += 1
		elif a[i] % 2 == 0:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


testcases = int(input())
for i in range(testcases):
	n = int(input())
	a = list(map(int, input().split()))
	(cnt1, cnt2) = (0, 0)
	for i in range(0, len(a)):
		if i % 2 == 0 and a[i] % 2 == 1:
			cnt1 += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			cnt2 += 1
	if cnt1 == cnt2:
		print(cnt1)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	e = 0
	od = 0
	if len(l) == 1:
		if l[0] % 2 == 0:
			print(0)
			continue
		else:
			print(-1)
			continue
	else:
		for i in range(len(l)):
			if i % 2 == 0 and l[i] % 2 != 0:
				e = e + 1
			elif i % 2 != 0 and l[i] % 2 == 0:
				od = od + 1
	if e == od:
		print(e)
	else:
		print(-1)


def isevev(d):
	return d % 2 == 0
t = int(input())
for i in range(t):
	n = int(input())
	li = [x for x in map(int, input().split())]
	ew = 0
	ow = 0
	for i in range(0, n, 2):
		if isevev(li[i]) == False:
			ew += 1
	for i in range(1, n, 2):
		if isevev(li[i]) == True:
			ow += 1
	if ow != ew:
		print(-1)
	else:
		print(ew)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
from math import *
import bisect
from decimal import *
getcontext().prec = 50
abc = 'abcdefghijklmnopqrstuvwxyz'

def fn(n):
	c = 0
	while n % 2 == 0:
		c += 1
		n //= 2
	return c
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		c = d = 0
		for i in range(n):
			if a[i] % 2 != i % 2:
				if i % 2:
					d += 1
				else:
					c += 1
		if c == d:
			print(c)
		else:
			print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def even_array(a, l):
	c = 0
	d = 0
	x = 0
	for i in range(l):
		if a[i] % 2 == 0:
			c += 1
		else:
			d += 1
	if d - c > 0 or c - d > 1:
		return -1
	else:
		for i in range(l):
			if i % 2 != a[i] % 2:
				x += 1
	if l == 1 and a[0] % 2 == 0:
		return 0
	elif l == 1 and a[0] % 2 != 0:
		return -1
	return x // 2
n = int(input())
for i in range(n):
	leng = int(input())
	arr = list(map(int, input().rstrip().split()))
	print(even_array(arr, leng))


t = int(input())
for _ in range(t):
	n = int(input())
	mas = [0] * n
	mods = [0] * n
	mods0 = 0
	mods1 = 0
	st = input()
	mas = st.split(' ')
	for i in range(0, n):
		if int(mas[i]) % 2 == i % 2:
			mods[i] = 0
		elif i % 2 == 1:
			mods1 += 1
		else:
			mods0 += 1
	if mods1 == mods0 and mods1 != 0:
		print(mods1)
	elif mods1 == 0 and mods0 == 0:
		print(0)
	else:
		print(-1)


t = int(input())

def evenarray(arr):
	ce = 0
	co = 0
	el = []
	ol = []
	for i in range(len(arr)):
		if i % 2 == 0:
			el.append(arr[i])
		else:
			ol.append(arr[i])
	for i in range(len(el)):
		if el[i] % 2 != 0:
			ce += 1
	for i in range(len(ol)):
		if ol[i] % 2 != 1:
			co += 1
	if ce == 0 and co == 0:
		print('0')
	elif ce == co:
		print(ce)
	else:
		print('-1')
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	evenarray(arr)


t = int(input())
for q in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	(a1, a2, b1, b2) = (0, 0, 0, 0)
	kol = 0
	for i in range(n):
		if i % 2 == 0:
			a1 += 1
		else:
			a2 += 1
		if arr[i] % 2 == 0:
			b1 += 1
		else:
			b2 += 1
		if i % 2 != arr[i] % 2:
			kol += 1
	if a1 != b1 or a2 != b2:
		print(-1)
	else:
		print(kol // 2)


n = int(input())
counter = 0
fin = []
while counter < n:
	a = int(input())
	b = input().split(' ')
	t = []
	steps = 0
	for x in b:
		t.append(int(x))
	(odd, even) = ([], [])
	for x in t:
		if x % 2 == 0:
			even.append(x)
		else:
			odd.append(int(x))
	if a == 1:
		if t[0] % 2 == 0:
			fin.append(0)
		else:
			fin.append(-1)
	elif a > 1 and (len(even) == len(odd) or len(even) - 1 == len(odd)):
		for i in range(a):
			if i % 2 == t[i] % 2:
				pass
			else:
				steps += 1 / 2
		fin.append(int(steps))
	else:
		fin.append(-1)
	counter += 1
for x in fin:
	print(int(x))


testcases = int(input())
for i in range(testcases):
	n = int(input())
	l = list(map(int, input().strip().split(' ')))
	example = []
	count0 = 0
	count1 = 0
	for i in range(len(l)):
		l[i] = l[i] % 2
		if l[i] == 0:
			count0 += 1
		else:
			count1 += 1
		if i % 2 == 0:
			example.append(0)
		else:
			example.append(1)
	if len(l) % 2 == 0:
		if count0 == count1:
			count = 0
			for i in range(len(l)):
				if example[i] == l[i]:
					pass
				else:
					count += 1
			if count % 2 == 0:
				print(int(count / 2))
			else:
				print(-1)
		elif len(l) == 1:
			if l[0] % 2 == 0:
				print(0)
			else:
				print(-1)
		else:
			print(-1)
	elif count1 + 1 == count0 or count0 + 1 == count1:
		count = 0
		for i in range(len(l)):
			if example[i] == l[i]:
				pass
			else:
				count += 1
		if count % 2 == 0:
			print(int(count / 2))
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	npp = 0
	pnp = 0
	even = 0
	n = int(input())
	tab = list(map(int, input().split()))
	for i in range(n):
		if tab[i] % 2 != 0 and i % 2 == 0:
			npp += 1
		elif tab[i] % 2 == 0 and i % 2 != 0:
			pnp += 1
	if pnp == npp:
		print(pnp)
	else:
		print(-1)


t = int(input())
while t > 0:
	lenth = int(input())
	inp = list(map(int, input().split()))
	odd_bad = 0
	even_bad = 0
	for i in range(lenth):
		if i % 2 != inp[i] % 2:
			if i % 2 == 1:
				odd_bad += 1
			else:
				even_bad += 1
	if odd_bad == 0 and even_bad == 0:
		print('0')
	elif odd_bad == even_bad:
		print(odd_bad)
	else:
		print('-1')
	t -= 1


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())
t = oint()
for _ in range(t):
	n = oint()
	a = list(rint())
	cnt0 = 0
	cnt1 = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			cnt0 += 1
		if i % 2 == 1 and a[i] % 2 == 0:
			cnt1 += 1
	if cnt0 == cnt1:
		print(cnt0)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	for i in range(0, n, 2):
		if arr[i] % 2 != 0:
			c1 += 1
	for i in range(1, n, 2):
		if arr[i] % 2 == 0:
			c2 += 1
	if c1 != c2:
		print('-1')
	else:
		print(c1)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	if len(li) == 1 and li[0] % 2 == 1:
		print(-1)
		continue
	(ei, oi) = ([], [])
	for i in range(n):
		if li[i] % 2 == 0:
			ei.append(i)
		else:
			oi.append(i)
	if len(li) % 2 == 0:
		if len(ei) == len(oi):
			ans = 0
			for i in ei:
				if i % 2:
					ans += 1
			for i in oi:
				if i % 2 == 0:
					ans += 1
			print(ans // 2)
		else:
			print(-1)
	elif len(ei) == len(oi) + 1:
		ans = 0
		for i in ei:
			if i % 2:
				ans += 1
		for i in oi:
			if i % 2 == 0:
				ans += 1
		print(ans // 2)
	else:
		print(-1)


from math import *

def f():
	n = int(input())
	a = list(map(int, input().split(' ')))
	e = 0
	o = 0
	for i in range(0, len(a)):
		if a[i] % 2 == 0:
			e += 1
		else:
			o += 1
	if e != ceil(n / 2):
		print(-1)
		return
	c = 0
	for i in range(0, len(a)):
		if i % 2 != a[i] % 2:
			c += 1
	print(c // 2)
for i in range(int(input())):
	f()


w = int(input())
for q in range(w):
	n = int(input())
	a = list(map(int, input().split()))
	cnt1 = 0
	cnt2 = 0
	for i in range(n):
		if i % 2 == 0 and i != 1:
			if a[i] % 2 != 0 or a[i] == 1:
				cnt1 += 1
		elif a[i] % 2 == 0 and a[i] != 1:
			cnt2 += 1
	if cnt1 != cnt2:
		print(-1)
	else:
		print(cnt1)


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	count_odd = 0
	count_even = 0
	for (idx, val) in enumerate(a):
		if val % 2 != idx % 2:
			if val % 2 == 0:
				count_even += 1
			else:
				count_odd += 1
	if count_even == count_odd:
		print(count_even)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	for j in range(n):
		if j % 2 != lst[j] % 2 and j % 2 == 0:
			c1 += 1
		elif j % 2 != lst[j] % 2 and j % 2 == 1:
			c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)


import math
n = int(input())
for i in range(n):
	b = int(input())
	c = input()
	l = c.split()
	l = list(map(int, l))
	kol_chetn = 0
	kol_nechet = 0
	kol_prav = 0
	for el in enumerate(l):
		if el[1] % 2 == 0:
			kol_chetn += 1
		else:
			kol_nechet += 1
		if el[0] % 2 == el[1] % 2:
			kol_prav += 1
	if kol_prav == b:
		print(0)
	elif b % 2 == 0:
		if kol_nechet == kol_chetn:
			print(int((b - kol_prav) / 2))
		else:
			print(-1)
	elif kol_nechet + 1 == kol_chetn:
		print(int((b - kol_prav) / 2))
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	a = input().split()
	b = []
	ch = 0
	nch = 0
	for i in range(len(a)):
		c = int(a[i]) % 2
		b.append(c)
		if c == 0 and i % 2 == 1:
			ch += 1
		elif c == 1 and i % 2 == 0:
			nch += 1
	if ch == nch:
		print(ch)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	A = [int(num) for num in input().split()]
	odds = sum((num % 2 == 1 for num in A))
	evens = n - odds
	if n % 2 == 0 and odds != evens:
		print(-1)
	elif n % 2 == 1 and odds != evens - 1:
		print(-1)
	else:
		count = 0
		for (i, num) in enumerate(A):
			count += i % 2 != num % 2
		print(count // 2)


t = int(input())
for tt in range(t):
	(k, k1) = (0, 0)
	n = int(input())
	a = input().split()
	for i in range(n):
		if int(a[i]) % 2 == 1:
			k1 -= 1
		else:
			k1 += 1
	if n % 2 == 1 and k1 == 1 or k1 == 0:
		for i in range(n):
			if i % 2 == 0 and int(a[i]) % 2 != 0:
				k += 1
			if i % 2 == 1 and int(a[i]) % 2 != 1:
				k += 1
		print(k // 2)
	else:
		print(-1)


def fuin(arr, n):
	p1 = 0
	p0 = 0
	if n % 2 == 0:
		p1 = n // 2
		p0 = n // 2
	else:
		p1 = n // 2
		p0 = n // 2 + 1
	pp0 = 0
	pp1 = 0
	misp = 0
	for ele in range(n):
		if arr[ele] % 2 == 0:
			pp0 += 1
			if ele % 2 != 0:
				misp += 1
		else:
			pp1 += 1
			if ele % 2 != 1:
				misp += 1
	if pp0 != p0 or pp1 != p1 or misp % 2 != 0:
		return -1
	elif misp % 2 == 0:
		return misp // 2
tc = int(input())
for _ in range(tc):
	n = int(input())
	arr = [int(x) for x in input().split()]
	print(fuin(arr, n))


import sys
import math
from sys import stdin, stdout

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def main():
	for t in range(int(input())):
		n = int(input())
		a = get_list()
		for i in range(n):
			a[i] = a[i] % 2
		odd = 0
		ev = 0
		o = 0
		e = 0
		for i in range(n):
			if a[i] == 0:
				ev += 1
			else:
				odd += 1
			if i % 2 == 0:
				e += 1
			else:
				o += 1
		if ev != e or o != odd:
			print('-1')
		else:
			c = 0
			for i in range(n):
				if a[i] == 0 and i % 2 == 1:
					c += 1
			print(c)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def process():
	n = int(input())
	arr = list(map(int, input().split()))
	badi = [0, 0]
	bade = [0, 0]
	for i in range(n):
		if i % 2 == 0:
			if arr[i] % 2 != 0:
				badi[0] += 1
				bade[1] += 1
		elif arr[i] % 2 == 0:
			badi[1] += 1
			bade[0] += 1
	if bade != badi:
		return -1
	else:
		return max(badi + bade)
for I in range(int(input())):
	print(process())


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	x = {}
	y = {}
	c = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				x[i] = a[i]
		if i % 2 == 1:
			if a[i] % 2 == 0:
				y[i] = a[i]
		if len(x) == len(y):
			c += len(x)
			x = {}
			y = {}
	if len(x) != len(y):
		print(-1)
	else:
		print(c)


def runnu(l):
	(even, odd) = (0, 0)
	x = 0
	for i in l:
		if x == 0:
			if i % 2 == 1:
				even += 1
			x = 1
		elif x == 1:
			if i % 2 == 0:
				odd += 1
			x = 0
	if even != odd:
		return -1
	return even
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(runnu(l))


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		(m, n) = (0, 0)
		for j in range(len(a)):
			if a[j] % 2 == 0 and j % 2 == 1:
				m = m + 1
			elif a[j] % 2 == 1 and j % 2 == 0:
				n = n + 1
		if m != n:
			print(-1)
		if m == 0 and n == 0:
			print(0)
		if m == n and n != 0:
			print(m)
main()


import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
import math
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	if n == 1:
		if a[0] % 2 == 0:
			print(0)
			continue
		else:
			print(-1)
			continue
	count1 = 0
	count2 = 0
	for i in range(len(a)):
		if i % 2 == 1 and a[i] % 2 == 0:
			count1 += 1
		elif i % 2 == 0 and a[i] % 2 == 1:
			count2 += 1
	if count1 != count2:
		print(-1)
		continue
	else:
		print(count1)


for l in range(int(input())):
	m = int(input())
	v = list(map(int, input().split()))
	a = []
	for j in range(m):
		if j % 2 == 0:
			if v[j] % 2 == 0:
				a.append(0)
			else:
				a.append('e')
		elif v[j] % 2 != 0:
			a.append(0)
		else:
			a.append('o')
	q1 = a.count('o')
	q2 = a.count('e')
	if q1 != q2:
		print(-1)
	else:
		print(q1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(aa, ab) = (0, 0)
	for i in range(n):
		if i % 2 == a[i] % 2:
			continue
		if i % 2 == 0:
			aa += 1
		else:
			ab += 1
	if aa == ab:
		print(aa)
	else:
		print(-1)


inp = lambda : int(input())
inpm = lambda : map(int, input().split())
inpl = lambda : list(inpm())

def solve():
	n = inp()
	a = inpl()
	wc = 0
	wn = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				wc += 1
		elif a[i] % 2 == 0:
			wn += 1
	if wc == wn:
		print(wc)
	else:
		print(-1)

def main():
	t = inp()
	for i in range(t):
		solve()
main()


def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def mi():
	return map(int, input().split())

def main():
	for i in range(ii()):
		n = ii()
		l = li()
		even = 0
		odd = 0
		right = 0
		for i in range(n):
			if l[i] % 2 == 0:
				even += 1
			else:
				odd += 1
			if i % 2 == l[i] % 2:
				right += 1
		if n % 2 == 0 and even != odd:
			print(-1)
			continue
		elif n % 2 != 0 and even != odd + 1:
			print(-1)
			continue
		else:
			print((n - right) // 2)
main()


def getAns(n, a):
	c = [0, 0]
	for (i, ai) in enumerate(a):
		q = i % 2
		if ai % 2 != q:
			c[q] += 1
	return c[0] if c[0] == c[1] else -1

def main():
	t = int(input())
	anss = [0] * t
	for i in range(t):
		n = input()
		a = list(map(int, input().split()))
		anss[i] = getAns(n, a)
	for ans in anss:
		print(ans)
main()


import collections

def read():
	return input().strip()

def readInt():
	return int(input().strip())

def readList():
	return list(map(int, input().strip().split()))

def solve(n, arr):
	evenIndices = (n + 1) // 2
	oddIndices = n - evenIndices
	(oddMismatch, evenMismatch) = (0, 0)
	(oddCounts, evenCounts) = (0, 0)
	for (i, num) in enumerate(arr):
		if num & 1:
			if not i & 1:
				oddMismatch += 1
			oddCounts += 1
		else:
			if i & 1:
				evenMismatch += 1
			evenCounts += 1
	if evenMismatch != oddMismatch:
		return -1
	return oddMismatch
t = readInt()
for i in range(t):
	n = readInt()
	arr = readList()
	print(solve(n, arr))


t = int(input())
for i in range(t):
	l = int(input())
	ind = 0
	count = 0
	x = 0
	for i in input().split():
		if int(i) % 2 == ind % 2:
			ind += 1
		else:
			if int(i) % 2 == 1:
				count += 1
			else:
				x += 1
			ind += 1
	if count != x:
		print(-1)
	else:
		print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	x = 0
	y = 0
	for i in range(n):
		if i % 2 == 0 and li[i] % 2 != 0:
			x += 1
		elif i % 2 != 0 and li[i] % 2 == 0:
			y += 1
	if x == y:
		print(x)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(len(a)):
		if i % 2 == a[i] % 2:
			pass
		elif a[i] % 2:
			odd += 1
		else:
			even += 1
	if odd != even:
		print(-1)
	else:
		print(even)


def solve():
	n = int(input())
	A = list(map(int, input().split()))
	a = filter(lambda x: x % 2 == 1 and A[x] % 2 != 1, range(n))
	b = filter(lambda x: x % 2 == 0 and A[x] % 2 != 0, range(n))
	t = len(list(a))
	if t == len(list(b)):
		print(t)
	else:
		print(-1)
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	par = []
	ans = []
	for i in range(n):
		par.append(arr[i] % 2)
		ans.append(i % 2)
	if par == ans:
		print(0)
	else:
		num = 0
		odd = 0
		even = 0
		for i in range(len(arr)):
			if par[i] != ans[i]:
				num += 1
				if i % 2 == 0:
					even += 1
				else:
					odd += 1
		if even != odd:
			print(-1)
		else:
			print(num // 2)


n = int(input())
for i in range(n):
	m = int(input())
	s = input().split(' ')
	a = []
	for j in s:
		a.append(int(j))
	chet = 0
	nechet = 0
	for j in range(len(a)):
		if j % 2 != a[j] % 2:
			if j % 2 == 0:
				nechet += 1
			else:
				chet += 1
	if chet != nechet:
		print(-1)
	else:
		print(min(chet, nechet))


import sys
input = sys.stdin.readline
from math import *
from random import randint
ttt = int(input())
test = 1
for test in range(ttt):
	n = int(input())
	cnt = 0
	jassala = 0
	ara = list(map(int, input().split()))
	for i in range(n):
		if ara[i] % 2 != i % 2:
			jassala = jassala + 1
		if ara[i] % 2 == 0:
			cnt = cnt + 1
	if cnt < n - cnt or abs(n - cnt - cnt) > 1:
		print('-1')
	else:
		print(int(jassala / 2))


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	yo = True
	for i in range(n):
		res = i % 2
		if lst[i] % 2 != res:
			yo = False
	if yo:
		print(0)
	else:
		odd = 0
		even = 0
		for i in lst:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
		if n % 2 == 0:
			if odd == even:
				cnt = 0
				for i in range(len(lst)):
					if lst[i] % 2 != i % 2:
						cnt += 1
				print(cnt // 2)
			else:
				print(-1)
		elif odd + 1 == even:
			cnt = 0
			for i in range(len(lst)):
				if lst[i] % 2 != i % 2:
					cnt += 1
			print(cnt // 2)
		else:
			print(-1)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	(c1, c2) = (0, 0)
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] % 2 == 0:
				continue
			else:
				c1 += 1
		elif l[i] % 2 == 0:
			c2 += 1
		else:
			continue
	if c1 == c2:
		print(c1)
	else:
		print(-1)
	t = t - 1


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	even = 0
	odd = 0
	for j in range(n):
		if l[j] % 2 == 0:
			even += 1
		else:
			odd += 1
	if n % 2 == 0 and even != odd:
		print(-1)
		continue
	elif n % 2 == 1 and even != odd + 1:
		print(-1)
		continue
	for j in range(n):
		if j % 2 == 0 and l[j] % 2 != 0:
			c += 1
		elif j % 2 == 1 and l[j] % 2 != 1:
			c += 1
	if c % 2 == 0:
		print(int(c / 2))
	else:
		print(-1)


from collections import defaultdict

def read_list():
	return list(map(int, input().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
N = int(input())
for _ in range(N):
	n = int(input())
	nums = read_list()
	zero = 0
	one = 0
	for k in nums[::2]:
		if k & 1:
			zero += 1
	for k in nums[1::2]:
		if k & 1 == 0:
			one += 1
	if zero == one:
		print(zero)
	else:
		print(-1)


import sys
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right
from collections import deque
from collections import Counter
from itertools import accumulate, combinations, permutations
from heapq import heapify, heappop, heappush
from functools import lru_cache

def input():
	return sys.stdin.readline()[:-1]

def printl(li):
	_ = print(*li, sep='\n') if li else None

def argsort(s, return_sorted=False):
	inds = sorted(range(len(s)), key=lambda k: s[k])
	if return_sorted:
		return (inds, [s[i] for i in inds])
	return inds

def alp2num(c, cap=False):
	return ord(c) - 97 if not cap else ord(c) - 65

def num2alp(i, cap=False):
	return chr(i + 97) if not cap else chr(i + 65)

def matmat(A, B):
	(K, N, M) = (len(B), len(A), len(B[0]))
	return [[sum([A[i][k] * B[k][j] for k in range(K)]) for j in range(M)] for i in range(N)]

def matvec(M, v):
	(N, size) = (len(v), len(M))
	return [sum([M[i][j] * v[j] for j in range(N)]) for i in range(size)]

def T(M):
	(n, m) = (len(M), len(M[0]))
	return [[M[j][i] for j in range(n)] for i in range(m)]

def main():
	mod = 1000000007
	N = int(input())
	A = tuple(map(int, input().split()))
	count1 = 0
	count2 = 0
	for (i, a) in enumerate(A):
		if i % 2 != a % 2:
			if a % 2 == 0:
				count1 += 1
			if a % 2 == 1:
				count2 += 1
	if count1 == count2:
		print(count1)
	else:
		print(-1)
q = int(input())
for _ in range(q):
	main()


def main():
	for t in range(int(input())):
		n = int(input())
		a = [int(i) for i in input().split()]
		om = 0
		em = 0
		for i in range(n):
			if i % 2 == 0:
				if a[i] % 2 != 0:
					em += 1
			elif a[i] % 2 != 1:
				om += 1
		if om == em:
			print(om)
		else:
			print(-1)
main()


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	counte = 0
	counto = 0
	for j in range(n):
		if j % 2 != l[j] % 2:
			if l[j] % 2 == 0:
				counte += 1
			else:
				counto += 1
	if counte == counto:
		print(counto)
	else:
		print('-1')


from math import ceil

def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	(odd, even) = (0, 0)
	for i in range(n):
		if lst[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	if n % 2 == 1 and even - odd != 1 or (n % 2 == 0 and even != odd):
		print(-1)
		return
	for i in range(n):
		if i % 2 != lst[i] % 2:
			lst[i] = -1
	print(lst.count(-1) // 2)
t = int(input())
for i in range(t):
	solve()


def numOfMoves(l):
	numMoves = 0
	array = []
	i = 0
	for i in range(len(l)):
		if l[i] % 2 == 0 and i % 2 == 1:
			if len(array) != 0:
				if array[len(array) - 1] == 1:
					array.remove(array[len(array) - 1])
					numMoves += 1
				else:
					array.append(0)
			else:
				array.append(0)
		if l[i] % 2 == 1 and i % 2 == 0:
			if len(array) != 0:
				if array[len(array) - 1] == 0:
					array.remove(array[len(array) - 1])
					numMoves += 1
				else:
					array.append(1)
			else:
				array.append(1)
	if len(array) != 0:
		return -1
	else:
		return numMoves

def isGood(l):
	isBad = True
	i = 0
	while i < len(l) and isBad:
		isBad = l[i] % 2 != i % 2
		i += 1
	return not isBad
t = int(input())
output = []
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	output.append(numOfMoves(l))
for _ in output:
	print(_)


def fun():
	n = int(input())
	a = [eval(x) for x in input().split()]
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 == a[i] % 2:
			continue
		elif i % 2 == 0 and a[i] % 2 != 0:
			odd += 1
		else:
			even += 1
	if odd == even == 0:
		return 0
	elif odd == even:
		return odd
	else:
		return -1
for z in range(int(input())):
	print(fun())


t = int(input())
for i in range(t):
	n = int(input())
	L = list(map(int, input().split()))
	count_odd = 0
	count_even = 0
	count = 0
	count_even_sai = 0
	for (j, l) in enumerate(L):
		if l % 2 == 0:
			count_even += 1
		else:
			count_odd += 1
	if abs(count_even - count_odd) >= 2 or count_odd > count_even:
		print(-1)
		continue
	for (j, l) in enumerate(L):
		if j % 2 != l % 2:
			count += 1
	print(count // 2)


t = int(input())
for each_t in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	actual = []
	actual_1 = 0
	actual_0 = 0
	real = []
	real_1 = 0
	real_0 = 0
	cnt = 0
	for i in range(n):
		actual.append(i % 2)
		if i % 2 == 0:
			actual_0 += 1
		else:
			actual_1 += 1
		real.append(a[i] % 2)
		if a[i] % 2 == 0:
			real_0 += 1
		else:
			real_1 += 1
	if actual_1 == real_1 and actual_0 == real_0:
		for (i, j) in zip(actual, real):
			if i != j:
				cnt += 1
		print(cnt // 2)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans1 = 0
	ans2 = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			if l[i] % 2 == 0:
				ans1 += 1
			else:
				ans2 += 1
	if ans1 == ans2:
		print(ans1)
	else:
		print(-1)


import sys
infile = sys.stdin
next(infile)
for line in infile:
	n = int(line)
	l = list(map(int, infile.readline().split()))
	rep = []
	odd = 0
	ev = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			rep.append(i)
			if i % 2 == 0:
				ev += 1
			else:
				odd += 1
	if ev != odd:
		print('-1')
	else:
		print(str(ev))


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	O = 0
	E = 0
	for i in range(n):
		if i % 2 != A[i] % 2:
			if i % 2 == 0:
				E += 1
			else:
				O += 1
	if O == E:
		print(O)
	else:
		print(-1)


def ques2(n, a):
	no = ne = po = pe = 0
	for i in range(n):
		if a[i] % 2 != 0:
			no += 1
		else:
			ne += 1
	if ne == no or no + 1 == ne:
		for i in range(n):
			if i % 2 == 0 and a[i] % 2 != 0:
				pe += 1
			elif i % 2 != 0 and a[i] % 2 == 0:
				po += 1
		print(int((po + pe) // 2))
	else:
		print(-1)
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = ques2(n, a)
	ans


T = int(input())
for i in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	a1 = []
	a2 = []
	f = True
	for j in range(len(a)):
		if j % 2 == 0:
			if a[j] % 2 == 0:
				continue
			else:
				a1.append(a[j])
		elif a[j] % 2 != 0:
			continue
		else:
			a2.append(a[j])
	if len(a1) == len(a2):
		print(len(a1))
	elif len(a1) != len(a2):
		print(-1)


for _ in range(int(input())):
	size = int(input())
	array = list(map(int, input().split()))
	even = 0
	odd = 0
	for (i, j) in enumerate(array):
		jmod = j % 2
		imod = i % 2
		if jmod == 0 and imod == 1:
			even += 1
		elif jmod == 1 and imod == 0:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
for x in range(t):
	n = int(input())
	li = [int(i) for i in input().split()]
	oc = 0
	ec = 0
	for i in range(len(li)):
		if i % 2 == 0:
			if li[i] % 2 == 1:
				oc += 1
		if i % 2 == 1:
			if li[i] % 2 == 0:
				ec += 1
	if oc == ec:
		print(oc)
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = []
	for i in range(n):
		if l[i] % 2 == 1 and i % 2 == 0:
			c.append(-1)
		elif l[i] % 2 == 0 and i % 2 == 1:
			c.append(1)
		else:
			c.append(0)
	f = c.count(-1)
	g = c.count(1)
	d = f - g
	if n == 1 and d == 1:
		print(-1)
	elif d != 0:
		print(-1)
	else:
		print((f + g) // 2)


t = int(input())

def fun(n, a):
	oe = 0
	eo = 0
	for i in range(n):
		if a[i] % 2 == i % 2:
			continue
		elif i % 2 == 0:
			eo += 1
		else:
			oe += 1
	if eo == oe:
		print(eo)
	else:
		print(-1)
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	fun(n, a)


def f():
	return int(input())
t = f()
for case in range(t):
	n = f()
	arr = list(map(int, input().split()))
	odd = even = 0
	for i in range(n):
		if i % 2:
			if arr[i] % 2 == 0:
				odd += 1
		elif arr[i] % 2:
			even += 1
	print(-1 if odd != even else odd)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	parity = [0, 0]
	for i in range(n):
		if i & 1 != a[i] & 1:
			parity[i & 1] += 1
	if parity[0] == parity[1]:
		print(parity[0])
	else:
		print(-1)


for _ in ' ' * int(input()):
	a = int(input())
	(_1, _0) = (0, 0)
	b = list(map(int, input().split()))
	for i in range(a):
		if i & 1 != b[i] & 1:
			if i & 1:
				_1 += 1
			else:
				_0 += 1
	if _1 == _0:
		print(_1)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	arr = list(map(int, s.split()))
	arr = [i % 2 for i in arr]
	count = 0
	if n % 2 == 0:
		if arr.count(1) == arr.count(0):
			for i in range(1, n, 2):
				if arr[i] != 1:
					count += 1
			print(count)
		else:
			print(-1)
	elif arr.count(0) - arr.count(1) == 1:
		for i in range(1, n, 2):
			if arr[i] != 1:
				count += 1
		print(count)
	else:
		print(-1)


q = int(input())
while q:
	q -= 1
	w = int(input())
	arr = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(w):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():

	def solve():
		n = int(inputi())
		aa = [int(a) for a in inputi().split()]
		odds = n // 2
		oc = len([a for a in aa if a % 2 == 1])
		if oc != odds:
			print(-1)
			return
		op = len([a for a in aa[::2] if a % 2 == 1])
		print(op)
	t = int(inputi())
	for _ in range(t):
		solve()
main()


for test_case in range(int(input())):
	size = int(input())
	array = list(map(int, input().split()))
	errors = 0
	even = 0
	odd = 0
	for (index, num) in enumerate(array):
		if index % 2 != 0 and num % 2 == 0:
			even += 1
			errors += 1
		elif index % 2 == 0 and num % 2 != 0:
			odd += 1
			errors += 1
	if errors == 0:
		print(0)
	elif errors % 2 != 0:
		print(-1)
	elif even == odd:
		print(errors // 2)
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	a = [int(ele) for ele in input().split()]
	(odd, even) = (0, 0)
	for i in range(len(a)):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				odd += 1
		elif a[i] % 2 == 0:
			even += 1
	if odd == even:
		print(odd)
	else:
		print(-1)
	t -= 1


for _ in range(int(input())):
	s = int(input())
	l = list(map(int, input().strip().split()))
	o = e = 0
	for i in range(s):
		if i & 1 != l[i] & 1:
			if i & 1 == 1:
				o += 1
			else:
				e += 1
	if o == e:
		print(o)
	else:
		print(-1)


def parity(lst):
	j = 0
	(odd, even) = (0, 0)
	for i in lst:
		if i % 2 == 0 and j % 2 != 0:
			even = even + 1
		elif i % 2 != 0 and j % 2 == 0:
			odd = odd + 1
		j = j + 1
	return (even, odd)
n = int(input())
for i in range(n):
	m = input()
	a = [int(i) for i in input().split()]
	(even, odd) = parity(a)
	if even == odd:
		print(even)
	else:
		print(-1)


for i in range(int(input())):
	ln = int(input())
	lst = list(map(int, input().split()))
	cap = [-1] * ln
	for i in range(ln):
		if i % 2 != lst[i] % 2:
			cap[i] = lst[i] % 2
	chet = 0
	nechet = 0
	for i in cap:
		if i == 1:
			nechet += 1
		elif i == 0:
			chet += 1
	if chet == nechet:
		print(chet)
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	a = [int(x) for x in input().split()]
	c = d = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				c += 1
			else:
				d += 1
	if c != d:
		print(-1)
	else:
		print(c)
	t -= 1


def main():
	t = int(input())
	for i in range(t):
		solve()

def solve():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	evens = 0
	odds = 0
	for i in arr:
		if i % 2 == 0:
			evens += 1
		else:
			odds += 1
	if evens != odds and n % 2 == 0 or (evens - 1 != odds and n % 2 == 1):
		print(-1)
		return
	total = 0
	for (index, i) in enumerate(arr):
		if i % 2 == 0 and index % 2 == 1:
			total += 1
	print(total)
main()


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(10000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	n = int(input())
	a = int_array()
	(ind_odd, num_odd, ind_even, num_even) = (0, 0, 0, 0)
	for i in range(n):
		if a[i] % 2 == 0:
			if i % 2 != 0:
				ind_even += 1
				num_odd += 1
		elif i % 2 == 0:
			ind_odd += 1
			num_even += 1
	if ind_odd == num_odd and ind_even == num_even:
		ans = (ind_odd + ind_even) // 2
		print(ans)
	else:
		print(-1)


def count_odd(a):
	return sum(map(lambda x: x % 2, a))
t = int(input())
for i in range(t):
	input()
	a = list(map(int, input().split()))
	if count_odd(a) != len(a) // 2:
		print(-1)
		continue
	errs_ = [0, 0]
	for j in range(len(a)):
		if (a[j] - j) % 2:
			errs_[j % 2] += 1
	print(max(errs_))


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	c = 0
	if n == 1:
		if a[0] % 2 == 0:
			print(0)
		else:
			print(-1)
	else:
		(even, odd) = (0, 0)
		for i in range(len(a)):
			if i % 2 == 0 and a[i] % 2 != 0:
				even += 1
			elif i % 2 != 0 and a[i] % 2 == 0:
				odd += 1
		if even != odd:
			print(-1)
		else:
			print(even)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	even = 0
	odd = 0
	for i in range(len(a)):
		if i % 2 == a[i] % 2:
			continue
		elif a[i] % 2 == 0:
			even = even + 1
		else:
			odd = odd + 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	(cnt0, cnt1, even, odd) = (0, 0, 0, 0)
	for i in range(n):
		if a[i] % 2:
			odd += 1
		else:
			even += 1
		if i % 2 == 0 and a[i] % 2 == 1:
			cnt1 += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			cnt0 += 1
	if n % 2 == 0 and even != odd:
		print(-1)
	elif n % 2 == 1 and even != odd + 1:
		print(-1)
	else:
		print(max(cnt0, cnt1))


t = int(input())
for i in range(t):
	ar = int(input())
	st = list(map(int, input().split(' ')))
	ct = 0
	ct1 = 0
	for i in range(ar):
		if i % 2 != st[i] % 2 and i % 2 == 0:
			ct1 += 1
		elif i % 2 != st[i] % 2 and i % 2 == 1:
			ct += 1
	if ct != ct1:
		print('-1')
	else:
		print(ct)


t = int(input())
for x in range(t):
	l = int(input())
	a = list(map(int, input().split()))
	(d, p) = (0, 0)
	for x in range(l):
		if x % 2 == 0:
			if a[x] % 2 != 0:
				d += 1
		elif a[x] % 2 != 1:
			p += 1
	if d + p > l or d != p:
		print(-1)
	else:
		print(d)


def justify(size, arr):
	even_odds = [0, 0]
	for i in range(size):
		rem = i % 2
		if rem != arr[i] % 2:
			even_odds[rem] = even_odds[rem] + 1
	if even_odds[0] == even_odds[1]:
		return even_odds[0]
	else:
		return -1
n = int(input())
for _ in range(n):
	size = int(input())
	arr = input().split(' ')
	arr = list(map(int, arr))
	print(justify(size, arr))


for _ in range(int(input())):
	a = int(input())
	b = list((int(x) for x in input().split()))
	odd = []
	even = []
	for i in range(a):
		if b[i] % 2 == i % 2:
			pass
		elif b[i] % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	el = len(even)
	ol = len(odd)
	if el == ol:
		print(el)
	else:
		print(-1)


n = int(input())
tests = [(int(input()), list(map(int, input().split()))) for _ in range(n)]
for test in tests:
	lst = test[1]
	length = test[0]
	evens = len(list(filter(lambda x: x % 2 == 0, lst)))
	if abs(length - evens * 2) > 1:
		print(-1)
		continue
	else:
		nabeja = 0
		for i in range(length):
			if i % 2 != lst[i] % 2:
				nabeja += 1
		if nabeja % 2 != 0:
			print(-1)
			continue
		print(nabeja // 2)


def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	even = 0
	odd = 0
	inc = 0
	for (i, e) in enumerate(a):
		if e % 2 == 0:
			even += 1
		else:
			odd += 1
		if e % 2 != i % 2:
			inc += 1
	if odd != n // 2 or even != n // 2 + n % 2:
		print(-1)
	else:
		print(inc // 2)
[solve() for i in range(int(input()))]


def sort(mass):
	a1 = []
	a0 = []
	flag = 0
	for i in range(len(mass)):
		if int(mass[i]) % 2 != i % 2:
			if int(mass[i]) % 2 == 1:
				a1.append(mass[i])
			else:
				a0.append(mass[i])
	if len(a0) == len(a1):
		flag = len(a0)
	else:
		flag = -1
	return flag

def inp():
	t = int(input(''))
	a_list = []
	for i in range(t):
		a = input()
		a_list.append(input('').split(' '))
	for i in a_list:
		print(sort(i))
inp()


n = int(input())
for i in range(n):
	x = int(input())
	arr = list(map(int, input().split()))
	e = 0
	o = 0
	for j in range(x):
		if j % 2 == 0 and arr[j] % 2 != 0:
			o += 1
		elif j % 2 == 1 and arr[j] % 2 == 0:
			e += 1
	if e == o:
		print(e)
	else:
		print(-1)


from sys import stdin

def input():
	return stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	d = 0
	for i in range(len(a)):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				c += 1
			else:
				d += 1
	if c != d:
		print(-1)
	else:
		print(c)


for _ in range(int(input())):
	n = int(input())
	a = []
	ctr = 0
	a = list(map(int, input().split()))
	if len(a) % 2 == 0:
		index_ones = n / 2
	else:
		index_ones = n // 2
	for i in range(n):
		if a[i] % 2 != 0:
			ctr = ctr + 1
	if index_ones != ctr:
		print(-1)
	else:
		i = 0
		ctr = 0
		while i < n:
			if a[i] % 2 != 0:
				ctr = ctr + 1
			i = i + 2
		print(ctr)


tc = int(input())
while tc:
	input()
	lst = map(int, input().strip().split())
	odd = even = 0
	for (i, val) in enumerate(lst):
		if i & 1:
			if not val & 1:
				odd += 1
		elif val & 1:
			even += 1
	print(odd if odd == even else -1)
	tc -= 1


test = int(input())
for t in range(test):
	n = int(input())
	a = [int(i) for i in input().split()]
	misplaced_odd = 0
	misplaced_even = 0
	if n > 1:
		for i in range(n):
			if i % 2 == 0 and a[i] % 2 != 0:
				misplaced_odd += 1
			elif i % 2 == 1 and a[i] % 2 == 0:
				misplaced_even += 1
		if misplaced_even - misplaced_odd == 0:
			print(misplaced_even)
		else:
			print('-1')
	elif n == 1:
		if a[0] % 2 != 0:
			print('-1')
		else:
			print('0')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	f = 0
	count = 0
	for (p, i) in enumerate(arr):
		if p & 1:
			if not i & 1:
				f -= 1
		elif i & 1:
			f += 1
			count += 1
	if f == 0:
		print(count)
	else:
		print(-1)


from functools import reduce
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	for i in range(inin()):
		n = inin()
		a = ain()
		count = 0
		odd = 0
		ev = 0
		for i in range(len(a)):
			if a[i] & 1 != i & 1:
				if i & 1 == 0:
					odd += 1
				else:
					ev += 1
				count += 1
		if odd == ev:
			print(count // 2)
		else:
			print(-1)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	tt = int(input())
	for test in range(tt):
		n = int(input())
		a = list(map(int, input().split()))
		(odd, even) = (0, 0)
		for i in range(n):
			if i % 2 == 0:
				if a[i] % 2 != 0:
					even += 1
			elif a[i] % 2 != 1:
				odd += 1
		if even == odd:
			print(even)
		else:
			print(-1)
main()


def solve(t):
	n = int(input())
	lst = list(map(int, input().split()))
	cnt = 0
	for i in range(len(lst)):
		if i % 2 != lst[i] % 2:
			for j in range(len(lst)):
				if i != j:
					if j % 2 != lst[j] % 2:
						if i % 2 == lst[j] % 2 and j % 2 == lst[i] % 2:
							(lst[i], lst[j]) = (lst[j], lst[i])
							cnt += 1
	for i in range(len(lst)):
		if i % 2 != lst[i] % 2:
			print(-1)
			return
	print(cnt)
t = int(input())
while t > 0:
	solve(t)
	t -= 1


t = int(input())
for g in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	eb = 0
	ob = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 == 1:
				eb += 1
		elif a[i] % 2 == 0:
			ob += 1
	if eb != ob:
		print(-1)
	else:
		print(eb)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input('').split()))
	ans = 0
	flag = 0
	for i in range(0, n, 2):
		if a[i] % 2 == 0:
			if i >= n - 1:
				continue
			if a[i + 1] % 2 == 1:
				continue
			else:
				x = n + 1
				for j in range(i + 2, n, 2):
					if a[j] % 2 == 1:
						x = j
						break
				if x < n:
					temp = a[i + 1]
					a[i + 1] = a[x]
					a[x] = temp
					ans += 1
				else:
					flag = -1
					break
		else:
			x = n + 2
			for k in range(i + 1, n, 2):
				if a[k] % 2 == 0:
					x = k
					break
			if x < n:
				temp = a[i]
				a[i] = a[x]
				a[x] = temp
				ans += 1
			else:
				flag = -1
				break
			if i >= n - 1:
				continue
			if a[i + 1] % 2 == 1:
				continue
			else:
				x = n + 2
				for l in range(i + 2, n, 2):
					if a[l] % 2 == 1:
						x = l
						break
				if x < n:
					temp = a[i + 1]
					a[i + 1] = a[x]
					a[x] = temp
					ans += 1
				else:
					flag = -1
					break
	if flag == 0:
		print(ans)
	else:
		print(flag)
	t -= 1


import os
import sys
t = int(input())
for k in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	cnt1 = 0
	cnt2 = 0
	for i in range(0, n):
		if i % 2 == 0:
			cnt1 += s[i] % 2
		else:
			cnt2 += s[i] % 2 == 0
	if cnt1 == cnt2:
		print(cnt1)
	else:
		print(-1)


import math
t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	eve = odd = 0
	eve_not_place = 0
	odd_not_place = 0
	for i in range(n):
		if a[i] % 2 == 0:
			eve += 1
		else:
			odd += 1
		if i % 2 == 0 and a[i] % 2 != 0:
			eve_not_place += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			odd_not_place += 1
	if eve != math.ceil(n / 2):
		print(-1)
	elif eve_not_place != odd_not_place:
		print(-1)
	else:
		print(eve_not_place)


k = int(input(''))
for i in range(k):
	n = int(input(''))
	s = input('')
	array = []
	array = list(s.split(' '))
	m = n % 2
	counteven = 0
	countodd = 0
	for i in range(n):
		if int(array[i]) % 2 == 0:
			counteven = counteven + 1
		else:
			countodd = countodd + 1
	if m == 1 and counteven != countodd + 1:
		print('-1')
	elif m == 0 and countodd != counteven:
		print('-1')
	else:
		extra = 0
		for i in range(n):
			c = i % 2
			if int(array[i]) % 2 != c:
				extra = extra + 1
			else:
				pass
		print(int(extra / 2))


answer = []
for i in range(int(input())):
	num = 0
	c = 0
	n = int(input())
	arr = list(map(int, input().split()))
	a1 = [j % 2 for j in range(n)]
	a2 = [j % 2 for j in arr]
	if a1 == a2:
		pass
	elif a1.count(0) != a2.count(0) or a1.count(1) != a2.count(1):
		num = -1
	else:
		for j in range(n):
			if a1[j] != a2[j]:
				c += 1
		if c % 2 == 0:
			num = c // 2
		else:
			num = c // 2 + 1
	answer.append(num)
for i in range(len(answer)):
	print(answer[i])


t = int(input())
for i in range(t):
	n = int(input())
	a = tuple(map(int, input().split()))
	count1 = 0
	count2 = 0
	res = 0
	if n % 2 == 0:
		for j in range(len(a)):
			if a[j] % 2 == 0:
				count2 += 1
				if j % 2 != 0:
					res += 1
			else:
				count1 += 1
		if count1 != count2:
			print(-1)
		else:
			print(res)
	else:
		for j in range(len(a)):
			if a[j] % 2 == 0:
				count2 += 1
				if j % 2 != 0:
					res += 1
			else:
				count1 += 1
		if count1 + 1 == count2:
			print(res)
		else:
			print(-1)


t = int(input())
for case in range(t):
	n = int(input())
	a = [int(s) for s in input().split(' ')]
	evens = len([x for x in a if x % 2 == 0])
	odds = len([x for x in a if x % 2 == 1])
	if odds != n // 2:
		answer = -1
	else:
		answer = sum([(a[i] - i) % 2 for i in range(n)]) // 2
	print(answer)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	even = 0
	o = 0
	f = 1
	for i in s:
		if i % 2 == 0:
			even += 1
		else:
			o += 1
	if n % 2 == 0:
		if even != o:
			print(-1)
			f = 0
	elif even - 1 != o:
		print(-1)
		f = 0
	if f:
		c = 0
		for i in range(n):
			if i % 2 != s[i] % 2:
				c += 1
		print(c // 2)


import sys

def input():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = 0
		c = 0
		for k in range(n):
			if k % 2 == 0:
				if a[k] % 2 != 0:
					b += 1
			elif a[k] % 2 != 1:
				c += 1
		if b != c:
			print(-1)
		else:
			print(b)
main()


t = int(input())
rpta = []
for i in range(t):
	lon = int(input())
	main = list(map(int, input().split()))
	count = 0
	pares = 0
	impares = 0
	for i in range(lon):
		if main[i] % 2 == 0 and i % 2 == 0 or (main[i] % 2 != 0 and i % 2 != 0):
			count = count + 1
		elif i % 2 == 0:
			impares = impares + 1
		else:
			pares = pares + 1
	count = lon - count
	if count == 0:
		rpta.append(0)
	elif pares == impares:
		rpta.append(count // 2)
	else:
		rpta.append(-1)
for j in rpta:
	print(j)


t = int(input())
for i in range(t):
	n = int(input())
	vetor = list(map(int, input().split()))
	pares = 0
	impares = 0
	foras = 0
	for a in range(n):
		if vetor[a] % 2 == 1:
			impares += 1
			if a % 2 == 0:
				foras += 1
		else:
			pares += 1
	if impares != n // 2:
		print(-1)
	else:
		print(foras)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	count = 0
	innerflag = False
	for i in range(len(arr)):
		if i % 2 != arr[i] % 2:
			j = i + 1
			while True:
				if j >= len(arr):
					print(-1)
					innerflag = True
					break
				if arr[j] % 2 != j % 2:
					temp = arr[i]
					arr[i] = arr[j]
					arr[j] = temp
					count += 1
					break
				j += 2
		if innerflag == True:
			break
	if innerflag == False:
		print(count)


for _ in range(int(input())):
	am = int(input())
	arr = list(map(int, input().split()))
	bad = [0, 0]
	fl = False
	for i in range(am):
		if arr[i] & 1 != i & 1:
			bad[i & 1] += 1
			fl = True
	if not fl:
		print(0)
	elif bad[0] != bad[1]:
		print(-1)
	else:
		print(bad[0])


t = int(input())
while t:
	e = 0
	o = 0
	f = 0
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(len(a)):
		if i % 2 == 0 and a[i] % 2 == 0 or (i % 2 == 1 and a[i] % 2 == 1):
			f += 1
		elif i % 2 == 0 and a[i] % 2 == 1:
			e += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			o += 1
	if f == n:
		print('0')
	elif e == o:
		print(e)
	else:
		print('-1')
	t = t - 1


def solve(l, arr):
	n1 = 0
	n2 = 0
	for i in range(0, l, 2):
		n1 += int(int(arr[i]) % 2 == 1)
	for i in range(1, l, 2):
		n2 += int(int(arr[i]) % 2 == 0)
	if n1 == n2:
		return n1
	else:
		return -1
t = int(input())
for i in range(t):
	l = int(input())
	arr = input().split(' ')
	print(solve(l, arr))


import os
import operator
import sys
from io import BytesIO, IOBase

def inar():
	return [int(el) for el in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = inar()
		res = 0
		for i in range(n):
			if i % 2 != arr[i] % 2:
				for j in range(i + 1, n):
					if j % 2 != arr[j] % 2 and j % 2 == arr[i] % 2:
						temp = arr[i]
						arr[i] = arr[j]
						arr[j] = temp
						res += 1
						break
		counter = 0
		for i in range(n):
			if i % 2 != arr[i] % 2:
				counter = 1
				break
		if counter == 1:
			print(-1)
		else:
			print(res)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
import sys

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphbates():
	return 'abcdefghijklmnopqrstuvwxyz'

def inp():
	ls = list(map(int, input().split()))
	return ls
t = int(input())
for _ in range(t):
	n = int(input())
	ls = inp()
	_0 = _1 = 0
	for i in range(n):
		if i % 2 == ls[i] % 2:
			continue
		elif i % 2 == 0 and ls[i] % 2 == 1:
			_0 += 1
		else:
			_1 += 1
	if _1 == _0:
		print(_0)
	else:
		print(-1)


t = int(input())
while t != 0:
	n = int(input())
	arr = []
	arr = [int(x) for x in input().split()]
	count1 = 0
	count2 = 0
	b = []
	c = []
	for i in range(len(arr)):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0 and arr[i] % 2 != 0:
				count1 += 1
			else:
				count2 += 1
	if count1 == count2:
		print(count1)
	else:
		print(-1)
	t = t - 1


t = int(input())
for z in range(t):
	q = input()
	a = list(map(int, input().split()))
	c = 0
	n = 0
	for i in range(0, len(a)):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				c += 1
			else:
				n += 1
	if c == n:
		print(c)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ch_num = 0
	ch_place = 0
	nech_num = 0
	nech_place = 0
	for i in range(len(arr)):
		if arr[i] % 2 == 0:
			ch_num += 1
			if i % 2 == 0:
				ch_place += 1
		else:
			nech_num += 1
			if i % 2 != 0:
				nech_place += 1
	if ch_num == ch_place and nech_num == nech_place:
		print(0)
	elif ch_num == nech_num or (len(arr) % 2 == 1 and ch_num - nech_num == 1):
		print(ch_num - ch_place)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	l = int(input())
	a = [int(x) for x in input().split()]
	even = 0
	for i in range(0, len(a), 2):
		if a[i] % 2 != 0:
			even += 1
	odd = 0
	for i in range(1, len(a), 2):
		if a[i] % 2 == 0:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		(oe, eo) = (0, 0)
		for (i, x) in enumerate(a):
			if i & 1 == x & 1:
				continue
			if i & 1:
				oe += 1
			if x & 1:
				eo += 1
		if oe != eo:
			print(-1)
		else:
			print(oe)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for tc in range(int(input())):
	n = int(input())
	a = [int(s) for s in input().split()]
	cnt = [0, 0]
	for (i, e) in enumerate(a):
		if i % 2 != e % 2:
			cnt[i % 2] += 1
	if cnt[0] != cnt[1]:
		print(-1)
	else:
		print(cnt[0])


tests = int(input())
for i in range(tests):
	n = int(input())
	a = [int(x) for x in input().split()]
	odd = 0
	even = 0
	position = 0
	for x in range(n):
		if a[x] % 2 == 0:
			even += 1
			if x % 2 != 0:
				position += 1
		else:
			odd += 1
			if x % 2 != 1:
				position += 1
	if odd == even or odd + 1 == even:
		print(position // 2)
	else:
		print(-1)


test = int(input())
for j in range(test):
	n = int(input())
	x = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0:
			if x[i] % 2 != 0:
				even += 1
		elif x[i] % 2 != 1:
			odd += 1
	if odd == even:
		print(even)
	else:
		print(-1)


def main():
	n = int(input())
	a = [int(s) for s in input().split()]
	sum1 = 0
	sum2 = 0
	for i in range(n):
		if i % 2 != a[i] % 2 and a[i] % 2 == 1:
			sum1 += 1
		if i % 2 != a[i] % 2 and a[i] % 2 == 0:
			sum2 += 1
	if sum1 == sum2:
		return sum1
	return -1
t = int(input())
for i in range(t):
	print(main())


import sys
import math
from math import factorial as f
from collections import defaultdict as dd
mod = 1000000007
T = 1
T = int(sys.stdin.readline())
for _ in range(T):
	n = int(input())
	l = list(map(int, input().split()))
	(c1, c2) = (0, 0)
	for i in range(n):
		if l[i] & 1:
			if i & 1 == 0:
				c1 += 1
		elif i & 1:
			c2 += 1
	if c1 != c2:
		print(-1)
	else:
		print(c1)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	arr = get_array()
	(oc, ec) = (0, 0)
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if arr[i] % 2 == 0:
				ec += 1
			else:
				oc += 1
	if oc == ec:
		print(oc)
	else:
		print(-1)


from sys import stdin

def solve(n, arr):
	wrongs = []
	for i in range(n):
		if i % 2 != arr[i] % 2:
			wrongs.append(i % 2)
	if len(wrongs) % 2 == 1:
		print(-1)
	else:
		n = len(wrongs)
		x = wrongs.count(1)
		if x != n / 2:
			print(-1)
		else:
			print(x)
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, stdin.readline().strip().split()))
	solve(n, arr)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	cnt = 0
	(ec, oc) = (0, 0)
	for i in range(n):
		if i % 2 == l[i] % 2:
			pass
		else:
			cnt += 1
	if cnt == 0:
		print(0)
	else:
		for i in range(n):
			if i % 2 != l[i] % 2:
				if i % 2 == 0:
					ec += 1
				else:
					oc += 1
		if ec == oc:
			print(ec)
		else:
			print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(ev, od) = (0, 0)
	for i in range(n):
		ev += i % 2 != l[i] % 2 and i % 2 == 0
		od += i % 2 != l[i] % 2 and i % 2 == 1
	print(ev if ev == od else -1)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	odd = []
	even = []
	cnt = 0
	cnt1 = 0
	for i in range(0, n):
		if i % 2 == 0 and a[i] % 2 != 0:
			cnt = cnt + 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			cnt1 = cnt1 + 1
	if cnt == cnt1:
		print(cnt)
	else:
		print(-1)
	t = t - 1


t = input()
for i in range(int(t)):
	n = input()
	aa = [int(a) for a in input().split()]
	if int(n) % 2 == 0:
		o = int(n) // 2
		e = int(n) // 2
	else:
		o = int(n) // 2
		e = int(n) // 2 + 1
	ans = 0
	o1 = 0
	e1 = 0
	for j in range(int(n)):
		if aa[j] % 2 == 0:
			e1 += 1
		else:
			o1 += 1
		if j % 2 != aa[j] % 2:
			ans += 1
	if o == o1 and e == e1:
		print(ans // 2)
	else:
		print(-1)


t = int(input())
for test in range(t):
	n = int(input())
	nums = [int(x) for x in input().split()]
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 == 1:
			if nums[i] % 2 == 0:
				odd += 1
		elif nums[i] % 2 == 1:
			even += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


def gogo(ls):
	evens = 0
	odds = 0
	for (i, num) in enumerate(ls):
		if num % 2 != i % 2:
			if num % 2 == 0:
				evens += 1
			else:
				odds += 1
	return evens if evens == odds else -1
t = int(input())
for i in range(t):
	ssdf = input()
	string = list(map(int, input().split()))
	print(gogo(string))


for _ in range(int(input())):
	n = input()
	li = list(map(int, input().split()))
	even_bad_count = 0
	odd_bad_count = 0
	for (idx, i) in enumerate(li):
		if i % 2 == 0:
			if idx % 2 != 0:
				even_bad_count += 1
		elif idx % 2 == 0:
			odd_bad_count += 1
	if even_bad_count == odd_bad_count:
		print(even_bad_count)
	else:
		print(-1)


import math
from collections import defaultdict, Counter

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	(odd_out_of_place, even_out_of_place) = (0, 0)
	for i in range(n):
		if i % 2 == 1 and arr[i] % 2 != 1:
			even_out_of_place += 1
		if i % 2 == 0 and arr[i] % 2 != 0:
			odd_out_of_place += 1
	if odd_out_of_place == even_out_of_place:
		print(even_out_of_place)
	else:
		print(-1)

def main():
	t = int(input())
	test_case_num = 1
	while test_case_num <= t:
		solve()
		test_case_num += 1
main()


i = int(input())
for j in range(i):
	l = int(input())
	arr = [int(k) for k in input().split(' ')]
	res = [0, 0]
	for k in range(l):
		if k % 2 == 0:
			if not arr[k] % 2 == 0:
				res[0] += 1
		elif not arr[k] % 2 == 1:
			res[1] += 1
	if res[0] == res[1]:
		print(res[0])
	else:
		print(-1)


num_tests = int(input())

def solve(n, nums):
	even_miss = 0
	odd_miss = 0
	for i in range(len(nums)):
		if i % 2 == 0 and nums[i] % 2 == 1:
			even_miss += 1
		elif i % 2 == 1 and nums[i] % 2 == 0:
			odd_miss += 1
	if even_miss == odd_miss:
		return even_miss
	else:
		return -1
for test in range(num_tests):
	n = int(input())
	nums = [int(x) for x in input().split(' ')]
	print(solve(n, nums))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	p = []
	l1 = [0] * n
	for (i, x) in enumerate(l):
		p.append(x % 2)
		if i % 2 != x % 2:
			l1[i] = 1
	(c1, c2) = (0, 0)
	for i in range(len(l)):
		if l1[i] == 1:
			if p[i] == 1:
				c1 += 1
			else:
				c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)


from collections import Counter
T = int(input())
for _ in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	arrparity = [arr[i] % 2 for i in range(len(arr))]
	indexparity = [i % 2 for i in range(len(arr))]
	if Counter(arrparity) != Counter(indexparity):
		print(-1)
	elif arrparity == indexparity:
		print(0)
	else:
		count = 0
		for i in range(len(arr)):
			if arrparity[i] != indexparity[i]:
				count += 1
		print(count // 2)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	o = []
	e = []
	flag = 1
	for i in range(n):
		if arr[i] % 2 == 0:
			e.append(arr[i])
		else:
			o.append(arr[i])
	if n % 2 == 1:
		if not (len(o) == (n - 1) // 2 and len(e) == (n + 1) // 2):
			flag = 0
			print(-1)
	elif not (len(o) == n // 2 and len(e) == n // 2):
		flag = 0
		print(-1)
	if flag == 1:
		c = 0
		for i in range(n):
			if arr[i] % 2 != i % 2:
				c += 1
		print(c // 2)


for __ in range(int(input())):
	n = int(input())
	A = [int(_) for _ in input().split()]
	(be, bo) = (0, 0)
	for (i, x) in enumerate(A):
		if i % 2 == x % 2:
			continue
		if i % 2:
			bo += 1
		else:
			be += 1
	print(be if be == bo else -1)


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	e = []
	o = []
	for (i, el) in enumerate(x):
		if i % 2 != el % 2:
			if i % 2 == 0:
				e.append(el)
			else:
				o.append(el)
	if len(e) == len(o):
		print(len(e))
	else:
		print(-1)


t = int(input())
for _t in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	o = 0
	for i in range(n):
		if arr[i] & 1 != 0:
			o += 1
	if n // 2 != o:
		print('-1')
	else:
		pos = [0] * n
		for i in range(n):
			if i & 1 != 0:
				if arr[i] & 1:
					pos[i] = 1
			elif arr[i] & 1 == 0:
				pos[i] = 1
		print(pos.count(0) // 2)


T = int(input())
for _ in range(T):
	N = int(input())
	A = [int(s) for s in input().split()]
	R = [0] * 2
	for i in range(N):
		if i % 2 != A[i] % 2:
			R[i % 2] += 1
	if R[0] != R[1]:
		print(-1)
	else:
		print(R[0])


n = int(input())
while n > 0:
	n -= 1
	l = int(input())
	arr = list(map(int, input().split()))
	i = 0
	a = []
	b = -1
	ans = 0
	while i < l:
		if arr[i] % 2 != i % 2:
			if len(a) == 0:
				a.append([arr[i], i])
			else:
				j = len(a) - 1
				f = 0
				while j >= 0:
					if a[j][0] % 2 == i % 2:
						ans += 1
						f = 1
						t = arr[i]
						arr[i] = a[j][0]
						arr[a[j][1]] = t
						a.pop(j)
						break
					j -= 1
				if f == 0:
					a.append([arr[i], i])
		i += 1
	if len(a) > 0:
		print(-1)
	else:
		print(ans)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from collections import Counter
from bisect import bisect_left
import sys
from queue import PriorityQueue
mod = 1000000007

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())

def printIn(ob):
	return stdout.write(str(ob) + '\n')

def powerLL(n, p):
	result = 1
	while p:
		if p & 1:
			result = result * n % mod
		p = int(p / 2)
		n = n * n % mod
	return result

def myCode():
	n = I()
	lst = L()
	odd_cnt = 0
	even_cnt = 0
	for i in range(len(lst)):
		if i % 2 == lst[i] % 2:
			continue
		elif lst[i] % 2 == 0:
			even_cnt += 1
		else:
			odd_cnt += 1
	if even_cnt == odd_cnt:
		print((odd_cnt + even_cnt) // 2)
	else:
		print(-1)

def main():
	for t in range(I()):
		myCode()
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = len(a)
	a1 = 0
	a2 = 0
	for i in range(d):
		if i % 2 == 0:
			if a[i] % 2 == 1:
				a2 = a2 + 1
		elif a[i] % 2 == 0:
			a1 = a1 + 1
	if a1 == a2:
		print(a1)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	e = 0
	o = 0
	for j in a:
		if j % 2 == 0:
			e += 1
		else:
			o += 1
	if o != n // 2:
		print(-1)
	else:
		j = 0
		p = 0
		while j < n:
			if a[j] % 2 != 0:
				p += 1
			j += 2
		print(p)


n = int(input())
for i in range(n):
	x = int(input())
	a = [int(i) for i in input().split()]
	(p, q) = (0, 0)
	for i in range(x):
		if i % 2 != a[i] % 2 and i % 2 == 0:
			p += 1
		elif i % 2 != a[i] % 2 and i % 2 == 1:
			q += 1
	if p != q:
		print(-1)
	else:
		print(p)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(evenp, oddp) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			evenp += 1
		elif i % 2 == 1 and arr[i] % 2 != 1:
			oddp += 1
	if evenp != oddp:
		print(-1)
	else:
		print(evenp)


t = int(input())
for i in range(t):
	n = int(input())
	s1 = input()
	s = s1.split()
	c = 0
	d = 0
	for j in range(n):
		if j % 2 == 0 and int(s[j]) % 2 != 0:
			c += 1
		elif j % 2 != 0 and int(s[j]) % 2 == 0:
			d += 1
	if c == d:
		print(c)
	else:
		print('-1')


t = int(input())
for _ in range(t):
	_ = int(input())
	A = list(map(int, input().split()))
	(oneZero, zeroOne) = (0, 0)
	for i in range(len(A)):
		if i % 2 == 0 and A[i] % 2 == 1:
			zeroOne += 1
		elif i % 2 == 1 and A[i] % 2 == 0:
			oneZero += 1
	if oneZero != zeroOne:
		print(-1)
	else:
		print(oneZero)


t = int(input())
for _ in range(t):
	n = int(input())
	a = str(input()).split(' ')
	e = 0
	o = 0
	for i in range(n):
		if int(a[i]) % 2 != i % 2 and int(a[i]) % 2 == 0:
			e += 1
		elif int(a[i]) % 2 != i % 2 and int(a[i]) % 2 != 0:
			o += 1
	if o == e:
		print(e)
	else:
		print('-1')


t = int(input())
while t > 0:
	t -= 1
	terms = int(input())
	lst = list(map(int, input().split()))
	lst1 = list()
	answer1 = 0
	answer2 = 0
	for (i, j) in enumerate(lst):
		lst1.append(i % 2)
		lst[i] = lst[i] % 2
		if lst1[i] == 1 and lst[i] == 0:
			answer1 += 1
		elif lst1[i] == 0 and lst[i] == 1:
			answer2 += 1
	if answer1 == answer2:
		print(answer1)
	else:
		print(-1)


t = int(input())
for T in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	(odd, even) = (0, 0)
	ans = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			odd += 1
		if i % 2 == 1 and a[i] % 2 == 0:
			even += 1
	ans = odd
	if odd != even:
		ans = -1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	countA = 0
	countB = 0
	ar = list(map(int, input().split()))
	for i in range(len(ar)):
		if i % 2 != ar[i] % 2:
			if i % 2 == 0:
				countA += 1
			else:
				countB += 1
	if countA != countB:
		print(-1)
	else:
		print(countA)


no_of_test_cases = int(input())
for i in range(no_of_test_cases):
	len_array = int(input())
	arr = list(map(int, input().split()))
	odd = even = 0
	for j in range(len_array):
		if j % 2 != arr[j] % 2:
			if j % 2 == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


def solution(A):
	oddparity = 0
	evenparity = 0
	for val in A[1::2]:
		oddparity += 1 if val % 2 == 0 else 0
	for val in A[::2]:
		evenparity += 1 if val % 2 == 1 else 0
	if oddparity != evenparity:
		return -1
	return oddparity

def parse():
	num = int(input().rstrip())
	for _ in range(num):
		_ = input()
		A = input().rstrip()
		print(solution(list(map(int, A.split(' ')))))
parse()


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sol = 0
	al = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				sol += 1
			else:
				al += 1
	if sol != al:
		print(-1)
	else:
		print(sol)


def EvenArray(n, a):
	fijada = []
	variable = []
	count = 0
	for (i, j) in enumerate(a):
		fijada.append(i % 2)
		variable.append(j % 2)
	if sorted(fijada) != sorted(variable):
		return -1
	else:
		for i in range(n):
			if fijada[i] != variable[i]:
				count += 1
		return int(count / 2)
Lista = []
total = int(input())
for i in range(total * 2):
	All = [int(i) for i in input().split()]
	Lista.append(All)
for j in range(0, len(Lista), 2):
	print(EvenArray(Lista[j][0], Lista[j + 1]))


I = input
t = int(I())
for tt in range(t):
	n = int(I())
	a = [int(x) for x in I().strip().split()]
	ce = 0
	co = 0
	for i in a:
		if i % 2 == 0:
			ce += 1
		else:
			co += 1
	if n % 2 == 0:
		if co != ce:
			print('-1')
		else:
			cnt = 0
			for i in range(len(a)):
				if i % 2 == 0 and a[i] % 2 != 0:
					cnt += 1
				if i % 2 != 0 and a[i] % 2 == 0:
					cnt += 1
			print(cnt // 2)
	elif ce != co + 1:
		print('-1')
	else:
		cnt = 0
		for i in range(len(a)):
			if i % 2 == 0 and a[i] % 2 != 0:
				cnt += 1
			if i % 2 != 0 and a[i] % 2 == 0:
				cnt += 1
		print(cnt // 2)


for j in range(int(input())):
	u = [0] * 2
	j = input()
	for (i, v) in enumerate(map(int, input().split())):
		u[i & 1] += i & 1 != v & 1
	print(u[0] if u[0] == u[1] else -1)


t = int(input())
rez = []
for i in range(t):
	n = int(input())
	ch = 0
	nch = 0
	a = input().split(' ')
	for j in range(n):
		a[j] = int(a[j])
		if j % 2 != a[j] % 2 and j % 2 == 1:
			nch += 1
		elif j % 2 != a[j] % 2 and j % 2 == 0:
			ch += 1
	if ch == nch:
		rez.append(ch)
	else:
		rez.append(-1)
for i in range(len(rez)):
	print(rez[i])


def f(l):
	n = 0
	for i in range(len(l)):
		if l[i] % 2 == 0:
			n += 1
	if len(l) % 2 == 0:
		e = len(l) // 2
	else:
		e = len(l) // 2 + 1
	return e == n
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	le = len(l)
	cnt = 0
	for i in range(le):
		if i % 2 != l[i] % 2:
			cnt += 1
	if cnt == 0:
		print(0)
	elif cnt % 2 == 0 and f(l):
		print(cnt // 2)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	count = 0
	b = []
	for i in range(n):
		if i % 2 == a[i] % 2:
			continue
		else:
			b.append(i)
	if len(b) % 2 != 0:
		print(-1)
	else:
		m = 0
		n = 0
		for j in range(len(b)):
			if a[b[j]] % 2 == 0:
				m += 1
			else:
				n += 1
		if m == n:
			print(m)
		else:
			print(-1)


import math
t = int(input())
for trial in range(t):
	int(input())
	a = list(map(int, input().split()))
	x = 0
	for i in range(len(a)):
		if a[i] % 2 == 0:
			x = x + 1
	even = math.ceil(len(a) / 2)
	if x != even:
		y = -1
	else:
		step = a[::2]
		y = 0
		for i in step:
			if i % 2 != 0:
				y = y + 1
	print(y)


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(j) for j in input().split()][:n]
	(a, b) = (0, 0)
	for k in range(n):
		if k % 2 == 0:
			if l[k] % 2 != 0:
				a += 1
		elif l[k] % 2 != 1:
			b += 1
	if a == b:
		print(a)
	else:
		print('-1')


import sys
data = sys.stdin.readlines()
filtered_data = []
for i in range(2, len(data)):
	if i % 2 == 0:
		filtered_data += [data[i].strip().split()]
for item in filtered_data:
	error_count = 0
	odd_count = 0
	even_count = 0
	for i in range(len(item)):
		if i % 2 == 0 and int(item[i]) % 2 != 0:
			error_count += 1
			odd_count += 1
		elif i % 2 != 0 and int(item[i]) % 2 == 0:
			error_count += 1
			even_count += 1
	if error_count % 2 != 0:
		print('-1')
	elif even_count != odd_count:
		print('-1')
	else:
		print(error_count // 2)


for i in range(int(input())):
	n = int(input())
	ae = 0
	ao = 0
	a = list(map(int, input().split()))
	count = 0
	for j in range(n):
		if a[j] % 2 == 0:
			ae += 1
		else:
			ao += 1
	if n % 2 != 0:
		if ae == ao + 1:
			for k in range(len(a)):
				if a[k] % 2 != k % 2 and a[k] % 2 != 0:
					count += 1
				else:
					continue
			print(count)
		else:
			print(-1)
	elif n % 2 == 0:
		if ae == ao:
			for k in range(len(a)):
				if a[k] % 2 != k % 2 and a[k] % 2 == 0:
					count += 1
				else:
					continue
			print(count)
		else:
			print(-1)


for _ in range(int(input())):
	n = int(input())
	q = [i % 2 for i in list(map(int, input().split()))]
	if sum(q) != n // 2:
		print(-1)
	else:
		res = 0
		for i in range(0, n, 2):
			res += q[i]
		print(res)


from sys import stdin
input = stdin.readline
for i in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	une = 0
	uno = 0
	for i in range(n):
		if i % 2 == 0:
			if li[i] % 2 == 0:
				continue
			else:
				une += 1
		elif li[i] % 2 == 1:
			continue
		else:
			uno += 1
	if une == uno:
		print(une)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = a[::2]
	y = a[1::2]
	x1 = 0
	y1 = 0
	for i in x:
		if i % 2 == 1:
			x1 += 1
	for i in y:
		if i % 2 == 0:
			y1 += 1
	if x1 != y1:
		print(-1)
	else:
		print(x1)


import math
for q in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	c1 = 0
	for i in range(n):
		if a[i] % 2 != i % 2 and i % 2 == 0:
			c += 1
		elif a[i] % 2 != i % 2 and i % 2 != 0:
			c1 += 1
	if c != c1:
		print(-1)
	else:
		print(c)


N = input()
for i in range(int(N)):
	oddcounter = 0
	evencounter = 0
	T = int(input())
	something = input().split()
	something = [int(x) for x in something]
	for n in range(T):
		if n % 2 != something[n] % 2:
			if n % 2 == 1:
				oddcounter += 1
			else:
				evencounter += 1
	if oddcounter == evencounter:
		print(oddcounter)
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	par = []
	cpar = []
	for i in range(n):
		par.append(lis[i] % 2)
		cpar.append(i % 2)
	m0 = []
	m1 = []
	for i in range(n):
		if par[i] != cpar[i]:
			if par[i] == 0:
				m0.append(i)
			else:
				m1.append(i)
	if len(m0) == len(m1):
		print(len(m0))
	else:
		print(-1)


t = int(input())
for i in range(t):
	a = int(input())
	b = list(map(int, input().split()))
	k = 0
	j = 0
	for i in range(a):
		if b[i] % 2 == 0 and i % 2 != 0:
			k += 1
		if b[i] % 2 != 0 and i % 2 == 0:
			j += 1
	if k == j:
		print(k)
	else:
		print(-1)
	b.clear()


import collections

def read():
	return input().strip()

def readInt():
	return int(input().strip())

def readList():
	return list(map(int, input().strip().split()))

def solve(n, arr):
	(oddMismatch, evenMismatch) = (0, 0)
	for (i, num) in enumerate(arr):
		if num & 1 and (not i & 1):
			oddMismatch += 1
		if not num & 1 and i & 1:
			evenMismatch += 1
	if evenMismatch != oddMismatch:
		return -1
	return oddMismatch
t = readInt()
for i in range(t):
	n = readInt()
	arr = readList()
	print(solve(n, arr))


t = int(input())
for i in range(t):
	l = int(input())
	nums = list(map(int, input().split()))
	(n_odd, n_even, count) = (0, 0, 0)
	for j in range(l):
		if j % 2 == 0:
			if nums[j] % 2 == 0:
				n_even += 1
			else:
				n_odd += 1
				count += 1
		elif nums[j] % 2 == 0:
			n_even += 1
		else:
			n_odd += 1
	if l % 2 == 0:
		if n_even != n_odd:
			print('-1')
		else:
			print(count)
	elif n_even != n_odd + 1:
		print('-1')
	else:
		print(count)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(em, om) = (0, 0)
	for i in range(n):
		if l[i] % 2 != i % 2:
			if i % 2 == 0:
				em += 1
			else:
				om += 1
	if em != om:
		print(-1)
	else:
		print(em)


n1 = int(input())
for i in range(n1):
	n2 = int(input())
	arr = [int(i) for i in input().split()]
	odd = even = 0
	for i in range(n2):
		if i % 2 != arr[i] % 2:
			if arr[i] % 2 != 0:
				odd += 1
			else:
				even += 1
	if odd != even:
		print(-1)
	else:
		print(even)


T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	odd = 0
	even = 0
	count = 0
	for i in range(N):
		if A[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if i % 2 == 0 and A[i] % 2 == 1 or (i % 2 == 1 and A[i] % 2 == 0):
			count += 1
	if N % 2 == 1 and even - odd == 1 or (N % 2 == 0 and odd == even):
		print(int(count / 2))
	else:
		print(-1)


test = int(input())
for t in range(test):
	n = int(input())
	a = list(map(int, input().split()[:n]))
	count1 = 0
	count2 = 0
	for x in range(0, n, 2):
		if a[x] % 2 != 0:
			count1 += 1
	for c in range(1, n, 2):
		if a[c] % 2 == 0:
			count2 += 1
	if count1 == count2:
		print(count1)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	x = [int(i) for i in input().split()]
	(e, o) = (0, 0)
	for i in range(len(x)):
		if i % 2 == 0 and x[i] % 2 != 0:
			o += 1
		elif i % 2 == 1 and x[i] % 2 != 1:
			e += 1
	if o != e:
		print(-1)
	else:
		print(o)


for i in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	par = 0
	e = 0
	o = 0
	for i in a:
		if par:
			if i & 1 == 0:
				e += 1
			par = 0
		else:
			if i & 1:
				o += 1
			par = 1
	if o == e:
		print(o)
	else:
		print(-1)


t = int(input())
for i in range(0, t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	ev = 0
	odd = 0
	ev_miss = 0
	odd_miss = 0
	for j in range(0, len(a)):
		if a[j] % 2 == 0:
			ev += 1
		else:
			odd += 1
		if j % 2 == 0 and a[j] % 2 != 0:
			ev_miss += 1
		elif j % 2 != 0 and a[j] % 2 != 1:
			odd_miss += 1
		else:
			pass
	if n % 2 == 0 and ev == odd or (n % 2 == 1 and ev == odd + 1):
		print(int((ev_miss + odd_miss) / 2))
	else:
		print('-1')


n = int(input())
for j in range(n):
	l = int(input())
	a = [int(x) for x in input().split()]
	b = [x % 2 for x in a]
	(c_0, c_1, w_0, w_1) = (0, 0, 0, 0)
	for i in range(l):
		if i % 2 == 0:
			if b[i] == 0:
				c_0 += 1
			else:
				w_1 += 1
		elif b[i] == 1:
			c_1 += 1
		else:
			w_0 += 1
	if w_0 == 0 and w_1 == 0:
		print(0)
	elif w_0 != w_1:
		print(-1)
	else:
		print(w_0)


t = int(input())
k = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	r1 = 0
	r2 = 0
	for j in range(len(a)):
		if a[j] % 2 != j % 2:
			if a[j] % 2 == 1:
				r1 += 1
			else:
				r2 += 1
	if r1 == r2:
		k.append(r1)
	else:
		k.append(-1)
for i in range(t):
	print(k[i])


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	oddsWrong = 0
	evenWrong = 0
	for (i, val) in enumerate(a):
		if i % 2 == 0 and val % 2 == 1:
			evenWrong += 1
		elif i % 2 == 1 and val % 2 == 0:
			oddsWrong += 1
	if oddsWrong == evenWrong:
		print(oddsWrong)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	input()
	arr = list(map(int, input().split()))
	d_even = 0
	d_odds = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			d_even += arr[i] % 2 != i % 2
		if i % 2 == 1:
			d_odds += arr[i] % 2 != i % 2
	if d_even == d_odds:
		print(d_even)
	else:
		print(-1)


t = int(input())
for z in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	zercount = 0
	onecount = 0
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 == 1:
			zercount += 1
		elif i % 2 == 1 and l[i] % 2 == 0:
			onecount += 1
	if zercount == onecount:
		print(zercount)
	else:
		print('-1')


inputn = int(input())
ans = []
for i in range(inputn):
	l = input()
	c = input()
	al = c.split()
	m = map(int, al)
	li = list(m)
	e = o = x = 0
	for j in li:
		if j % 2 != x:
			if x == 1:
				o = o + 1
			else:
				e = e + 1
		x = 1 - x
	if o == e:
		ans.append(o)
	else:
		ans.append(-1)
for i in ans:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	e = sum((i % 2 == 0 for i in arr))
	o = sum((i % 2 == 1 for i in arr))
	if len(arr) == 1 and arr[0] % 2 == 1:
		print('-1')
	elif len(arr) % 2 == 0 and o != e:
		print('-1')
	elif len(arr) % 2 == 1 and e - o != 1:
		print('-1')
	else:
		res = 0
		i = 0
		while i < len(arr):
			if arr[i] % 2 != i % 2:
				res += 1
			i += 1
		print(res // 2)


def case1(arr):
	count = 0
	for i in range(0, len(arr), 2):
		if arr[i] % 2 != 0:
			count += 1
	return count

def case2(arr):
	count = 0
	for i in range(1, len(arr), 2):
		if arr[i] % 2 != i % 2:
			count += 1
	return count
ans = []
asd = -1
for i in range(int(input())):
	d = int(input())
	arr = list(map(int, input().rstrip().split()))
	if case1(arr) == case2(arr):
		ans.append(case1(arr))
	else:
		ans.append(asd)
for i in ans:
	print(i)


def calc(n, arr):
	count = 0
	for i in range(0, n):
		if arr[i] % 2 != i % 2:
			flag = False
			for j in range(i + 1, n):
				if arr[j] % 2 != j % 2 and arr[i] % 2 != arr[j] % 2:
					(arr[i], arr[j]) = (arr[j], arr[i])
					count += 1
					flag = True
					break
			if not flag:
				return -1
	return count
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(calc(n, arr))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ue = 0
	uo = 0
	for i in range(n):
		if arr[i] % 2 != i % 2:
			if i % 2 == 0:
				ue += 1
			else:
				uo += 1
	if ue != uo:
		print(-1)
	else:
		print(ue)


t = int(input())
for i in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	count = 0
	for j in range(len(lis)):
		if j % 2 == lis[j] % 2:
			pass
		else:
			for k in range(j, len(lis)):
				if j % 2 == lis[k] % 2 and k % 2 != lis[k] % 2:
					temp = lis[k]
					lis[k] = lis[j]
					lis[j] = temp
					count = count + 1
					break
				elif k == len(lis) - 1:
					count = -1
					break
	print(count)


def foo(sizeOfArray, l):
	countOdd = 0
	countEven = 0
	for i in range(0, sizeOfArray, 2):
		if l[i] % 2 == 1:
			countOdd = countOdd + 1
	for i in range(1, sizeOfArray, 2):
		if l[i] % 2 == 0:
			countEven = countEven + 1
	if countEven == countOdd:
		return countOdd
	else:
		return -1
n = input()
n = int(n)
answers = list()
for i in range(n):
	sizeOfArray = input()
	sizeOfArray = int(sizeOfArray)
	l = [int(x) for x in input().split()]
	answers.append(foo(sizeOfArray, l))
for i in answers:
	print(i)


def solve():
	badones = 0
	badzeroes = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			if arr[i] % 2 != 0:
				badones += 1
		elif arr[i] % 2 == 0:
			badzeroes += 1
	if badones != badzeroes:
		return -1
	else:
		return badones
testcases = int(input())
for i in range(testcases):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve())


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	odd = 0
	even = 0
	count = 0
	for i in range(n):
		if s[i] % 2 != 0:
			even += 1
		else:
			odd += 1
		if (i + 1) % 2 == s[i] % 2:
			count += 1
	if odd != n // 2 + n % 2 or even != n // 2:
		print(-1)
		continue
	print(count // 2)


t = int(input())
for x in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	even = 0
	odd = 0
	for i in range(n):
		if arr[i] % 2:
			odd += 1
		else:
			even += 1
	if n % 2:
		if even - odd == 1:
			wrong = 0
			for i in range(n):
				if arr[i] % 2 == 1 and i % 2 != 1:
					wrong += 1
				elif arr[i] % 2 == 0 and i % 2 != 0:
					wrong += 1
			print(int(wrong / 2))
			continue
		else:
			print(-1)
			continue
	elif n % 2 == 0:
		if even != odd:
			print(-1)
			continue
		else:
			wrong = 0
			for i in range(n):
				if arr[i] % 2 == 1 and i % 2 != 1:
					wrong += 1
				elif arr[i] % 2 == 0 and i % 2 != 0:
					wrong += 1
			print(int(wrong / 2))
			continue


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = [int(i) % 2 for i in input().split()]
	count0 = list1.count(0)
	count1 = list1.count(1)
	list2 = [int(i) % 2 for i in range(n)]
	if list1 == list2:
		print(0)
	elif n % 2 == 0 and count0 != count1:
		print(-1)
	elif n % 2 != 0 and count0 - count1 != 1:
		print(-1)
	else:
		res = [i for (i, j) in zip(list1, list2) if i != j]
		print(int(len(res) / 2))


from sys import stdin, stdout, setrecursionlimit
for _ in range(int(input())):
	n = int(input())
	a = [int(i) % 2 for i in input().split()]
	cou0 = cou1 = 0
	for x in a:
		if x == 0:
			cou0 += 1
		else:
			cou1 += 1
	x = 0
	if cou0 == cou1 + n % 2:
		for i in range(n):
			if i % 2 != a[i]:
				x += 1
		print(x // 2)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	m = 0
	a = [int(x) for x in input().split()]
	for i in range(n):
		if a[i] % 2 == 1:
			m += 1
		if i % 2 != a[i] % 2:
			c += 1
	if c % 2 == 1 or m != n // 2:
		print(-1)
	else:
		print(c // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	d = 0
	dd = 0
	same = 0
	l = list(map(int, input().split()))
	for i in range(len(l)):
		if i % 2 == 0 and l[i] % 2 != 0:
			d += 1
		elif i % 2 != 0 and l[i] % 2 == 0:
			dd += 1
	if d == dd:
		print(dd)
	else:
		print(-1)


size = int(input())
for i in range(size):
	l_size = input()
	even = 0
	odd = 0
	ls = list(map(int, input().split()))
	for i in range(len(ls)):
		if i % 2 == 0:
			if ls[i] % 2 == 0:
				pass
			else:
				even += 1
		elif i % 2 != 0:
			if ls[i] % 2 != 0:
				pass
			else:
				odd += 1
	if even == odd:
		print(even)
	elif even == 0 and odd == 0:
		print(even)
	else:
		print(-1)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	n = int(sys.stdin.readline())
	list_num = list(map(int, sys.stdin.readline().split()))
	check = [0, 0]
	for i in range(n):
		if not i % 2 == list_num[i] % 2:
			check[i % 2] += 1
	if check[0] == check[1]:
		print(check[0])
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	out = 0
	for i in range(n):
		if a[i] % 2 == 1:
			odd += 1
			if i % 2 == 0:
				out += 1
	if odd != n // 2:
		print(-1)
	else:
		print(out)


def main():
	t = int(input())
	for __ in range(t):
		n = int(input())
		odd = 0
		even = 0
		a = list(map(int, input().split()))
		for i in range(n):
			if i % 2 != a[i] % 2:
				if i % 2:
					odd += 1
				else:
					even += 1
		if odd == even:
			print(odd)
		else:
			print(-1)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	cnt2 = 0
	for i in range(n):
		if a[i] & 1:
			cnt += 1
			if i % 2 == 0:
				cnt2 += 1
	if cnt == n // 2:
		print(cnt2)
	else:
		print(-1)


tc = int(input())
while tc:
	n = int(input())
	arr = list(map(int, input().split(' ')))
	swaps = 0
	flag = False
	for i in range(n):
		count = 0
		for j in range(n):
			if j % 2 == arr[j] % 2:
				count += 1
			else:
				for k in range(j, n, 1):
					if j % 2 == arr[k] % 2 and arr[k] % 2 != k % 2:
						(arr[j], arr[k]) = (arr[k], arr[j])
						swaps += 1
						break
		if count == n:
			print(swaps)
			flag = True
			break
	if not flag:
		print(-1)
	tc -= 1


for _ in range(int(input())):
	n = int(input())
	good = []
	bad = []
	a = list(map(int, input('').strip().split()))[:n]
	for i in range(len(a)):
		if i % 2 == 0 and a[i] % 2 != 0:
			good.append(a[i])
		if i % 2 != 0 and a[i] % 2 == 0:
			bad.append(a[i])
	x = len(bad) - len(good)
	if x == 0:
		print(int(len(good)))
	else:
		print('-1')


def f(arr):
	even = True
	e = 0
	ne = 0
	for a in arr:
		r = a % 2
		if r == 0 and (not even):
			ne += 1
		if r and even:
			e += 1
		even = not even
	if ne == e:
		return ne
	return -1
t = int(input())
for i in range(t):
	n = input()
	arr = [int(s) for s in input().split()]
	print(f(arr))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(s) for s in input().split()]
	cntodd = 0
	cnteven = 0
	for i in range(0, len(a)):
		if a[i] % 2 == 0 and i % 2 == 1:
			cntodd += 1
		elif a[i] % 2 == 1 and i % 2 == 0:
			cnteven += 1
	if cntodd != cnteven:
		print(-1)
	else:
		print(cntodd)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	eve = 0
	for i in range(n):
		if a[i] % 2 and i % 2 == 0:
			odd += 1
		if a[i] % 2 == 0 and i % 2:
			eve += 1
	if eve == odd:
		print(odd)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	odd_p = 0
	even_p = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			odd_p += 1
		elif i % 2 == 1 and arr[i] % 2 == 0:
			even_p += 1
	if odd_p == even_p:
		print(even_p)
	else:
		print(-1)


test_cases = int(input())
for z in range(test_cases):
	n = int(input())
	a = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if a[i] % 2 == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


n = int(input())
for i in range(n):
	j = 0
	c1 = 0
	c2 = 0
	c3 = 0
	c4 = 0
	m = int(input())
	a = list(map(int, input().split(' ')))
	if m % 2 == 0:
		d = m // 2
	else:
		d = m // 2 + 1
	for j in range(m):
		if a[j] % 2 == 0:
			c1 += 1
		if j % 2 == 0:
			if a[j] % 2 == 0:
				c2 += 1
			else:
				c3 += 1
	if c2 == d and c2 == c1:
		print(0)
	elif c1 != d:
		print(-1)
	else:
		print(c3)


import sys

def solve():
	even = 0
	odd = 0
	for w in range(n):
		if a[w] % 2 == 0:
			even += 1
		else:
			odd += 1
	if n % 2 == 0:
		if even != odd:
			return -1
	elif odd != even - 1:
		return -1
	ctr = 0
	for g in range(n):
		if a[g] % 2 != g % 2:
			ctr += 1
	return ctr // 2
T = int(sys.stdin.readline())
ans_arr = []
for t in range(T):
	n = int(sys.stdin.readline())
	a = [int(i) for i in sys.stdin.readline().split()]
	ans_arr.append(str(solve()))
print('\n'.join(ans_arr))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	neve = 0
	nodd = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			nodd += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			neve += 1
	if nodd != neve:
		print(-1)
	else:
		print(neve)


from sys import stdin, stdout
from sys import maxsize

def solve(a, n):
	(v1, v2) = (0, 0)
	for i in range(0, n, 2):
		if a[i] % 2 == 1:
			v1 += 1
	for i in range(1, n, 2):
		if a[i] % 2 == 0:
			v2 += 1
	if v1 == v2:
		print(v1)
	else:
		print(-1)
	pass
test = 1
test = int(input())
for t in range(0, test):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = solve(arr, n)


import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
tc = int(input())
for zzz in range(tc):
	n = int(input())
	arr = list(map(int, input().split()))
	jor = cha = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			jor += 1
			if i % 2 != 0:
				cha += 1
	jorghor = n - n // 2
	if jor != jorghor:
		print(-1)
	else:
		print(cha)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = []
	b = []
	for i in range(n):
		a.append(l[i] % 2)
		b.append(i % 2)
	for i in range(n):
		if a[i] == b[i]:
			(a[i], b[i]) = (2, 2)
		else:
			pass
	if a.count(1) == b.count(1) and a.count(0) == b.count(0):
		print(a.count(0))
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	swap_even = 0
	count_even = 0
	swap_odd = 0
	count_odd = 0
	for j in range(n):
		if l[j] % 2 == 1:
			count_odd += 1
			if j % 2 == 0:
				swap_odd += 1
		else:
			count_even += 1
			if j % 2 == 1:
				swap_even += 1
	if n % 2 == 0:
		if count_even != count_odd:
			print(-1)
		else:
			print(min(swap_even, swap_odd))
	elif count_even - 1 != count_odd:
		print(-1)
	else:
		print(min(swap_even, swap_odd))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(e, o) = (0, 0)
	for (i, x) in enumerate(a):
		if i % 2 == 0 and x % 2 != 0:
			e += 1
		elif i % 2 != 0 and x % 2 == 0:
			o += 1
	if e == o:
		print(e)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(even, odd) = (0, 0)
	check = True
	for i in range(n):
		if check:
			if a[i] % 2 != 0:
				even += 1
			check = False
		else:
			if a[i] % 2 == 0:
				odd += 1
			check = True
	if even == odd == 0:
		print(0)
	elif even != odd:
		print(-1)
	else:
		print(even)


q = int(input())
for _ in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	(x, y) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			x += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			y += 1
	if x == y:
		print(x)
	else:
		print(-1)


def bad_parity_indices(arr):
	bad = [idx for idx in range(len(arr)) if idx % 2 != arr[idx] % 2]
	return bad

def check_parity(arr):
	return len(bad_parity_indices(arr)) == 0

def solvable(arr):
	bad = bad_parity_indices(arr)
	parity_check = 0
	for idx in bad:
		if arr[idx] % 2 == 0:
			parity_check += -1
		else:
			parity_check += 1
	return parity_check == 0
assert check_parity([0, 5, 2, 1])
assert check_parity([0, 17, 0, 3])
assert not check_parity([2, 4, 6, 7])
assert bad_parity_indices([2, 4, 6, 7]) == [1]
assert not solvable([1, 1])

def solve(arr):
	if not solvable(arr):
		return -1
	bad = bad_parity_indices(arr)
	if len(bad) % 2 == 0:
		return len(bad) // 2
	else:
		return -1
assert solve([3, 2, 7, 6]) == 2
assert solve([3, 2, 6]) == 1
assert solve([7]) == -1
assert solve([4, 9, 2, 1, 18, 3, 0]) == 0
assert solve([1, 1]) == -1

def main():
	T = int(input())
	for _ in range(T):
		arr_len = int(input())
		arr = list(map(int, input().split(' ')))
		print(solve(arr))
main()


total = int(input())
for _ in range(total):
	array_length = input().strip()
	array = input().strip().split(' ')
	array = [int(x) for x in array]
	even_wrong = 0
	odd_wrong = 0
	for (i, val) in enumerate(array):
		if i % 2 == 0 and i % 2 != val % 2:
			odd_wrong += 1
		elif i % 2 == 1 and i % 2 != val % 2:
			even_wrong += 1
	if odd_wrong != even_wrong:
		print(-1)
	else:
		print(odd_wrong)


import sys
TEST = 0
if TEST == 1:
	input_file = open('inputB.txt', 'r')
	input_from_file = input_file.readlines()

def read_int():
	if TEST:
		return int(input_from_file.pop(0))
	else:
		return int(sys.stdin.readline())

def read_ints():
	if TEST:
		return list(map(int, input_from_file.pop(0).rstrip().split()))
	else:
		return list(map(int, sys.stdin.readline().split()))

def read_str():
	if TEST:
		in1 = input_from_file.pop(0).rstrip()
	else:
		in1 = sys.stdin.readline().rstrip()
	return in1
tests = read_int()
for test in range(tests):
	n = read_int()
	a = read_ints()
	odd = 0
	even = 0
	for i in range(len(a)):
		if i & 1 and (not a[i] & 1):
			odd += 1
		if not i & 1 and a[i] & 1:
			even += 1
	if odd != even:
		ans = -1
	else:
		ans = odd
	print(ans)


def chet(m):
	k = 0
	for i in m:
		if i % 2 == 0:
			k += 1
	return k

def nechet(m):
	k = 0
	for i in m:
		if i % 2 != 0:
			k += 1
	return k
for i in range(int(input())):
	kol = 0
	n = int(input())
	m = [int(a) for a in input().split()]
	if n == 1:
		kol = -1
		if m[0] % 2 == 0:
			kol = 0
	elif n % 2 == 0 and chet(m) == nechet(m):
		for j in range(n):
			if j % 2 == 0 and j % 2 != m[j] % 2:
				kol += 1
	elif n % 2 != 0 and chet(m) == nechet(m) + 1:
		for j in range(n):
			if j % 2 == 0 and j % 2 != m[j] % 2:
				kol += 1
	else:
		kol = -1
	print(kol)


tc = int(input())
for i in range(tc):
	n = int(input())
	cnt_odd = 0
	cnt_even = 0
	num = [int(i) for i in input().split()]
	for j in range(len(num)):
		if (j + num[j]) % 2 == 0:
			continue
		elif num[j] % 2 == 0:
			cnt_even += 1
		else:
			cnt_odd += 1
	if cnt_odd == cnt_even:
		print(cnt_odd)
	else:
		print('-1')


t = int(input())
while t > 0:
	a = int(input())
	n = list(map(int, input().split()))
	oddcounter = 0
	evencounter = 0
	for i in range(len(n)):
		if n[i] % 2 == 0:
			evencounter += 1
		else:
			oddcounter += 1
	if a % 2 == 0 and evencounter == oddcounter:
		wrongpcounter = 0
		for k in range(0, len(n), 2):
			if n[k] % 2 == 1:
				wrongpcounter += 1
			else:
				continue
		print(wrongpcounter)
	elif a % 2 == 1 and evencounter == oddcounter + 1:
		wc = 0
		for x in range(0, len(n), 2):
			if n[x] % 2 == 1:
				wc += 1
			else:
				continue
		print(wc)
	else:
		print('-1')
	t -= 1


T = int(input())
B = []
for k in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	b = 0
	c = 0
	for i in range(N):
		if i % 2 == 0:
			if A[i] % 2 == 0:
				continue
			else:
				b += 1
		elif i % 2 == 1:
			if A[i] % 2 == 1:
				continue
			else:
				c += 1
	if b == c:
		B.append(b)
	else:
		B.append(-1)
for i in B:
	print(i)


def func(a):
	a = list(map(int, a.split()))
	if len(a) % 2 == 0:
		odd = even = len(a) // 2
	else:
		odd = len(a) // 2
		even = odd + 1
	if len([i for i in a if i % 2 == 0]) != even:
		return -1
	zipped = zip([i % 2 for i in a], [i % 2 for i in range(len(a))])
	zipped = list(zipped)
	swap = sum([1 for i in zipped if i[0] != i[1]])
	if swap % 2 == 0:
		return swap // 2
	else:
		return (swap + 1) // 2

def main():
	t = int(input())
	input_list = []
	for i in range(t):
		input()
		input_list.append(input())
	for i in list(map(func, input_list)):
		print(i)
main()


T = int(input())
for t in range(T):
	n = int(input())
	A = [int(i) % 2 for i in input().split()]
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 != A[i] % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if odd != even:
		print(-1)
	else:
		print(even)


t = int(input())
for j in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	odds = []
	evens = []
	for i in range(0, len(a)):
		if i % 2 == 0 and a[i] % 2 == 1:
			odds.append(a[i])
		elif i % 2 == 1 and a[i] % 2 == 0:
			evens.append(a[i])
	if len(evens) != len(odds):
		print('-1')
	else:
		print(len(evens))


def solve(n, ar):
	cnt = 0
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 == 0:
			if ar[i] % 2 == 0:
				continue
			else:
				even += 1
		elif ar[i] % 2 != 0:
			continue
		else:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)
t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	solve(n, ar)


for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	wrong0 = sum([1 if a[i] % 2 != i % 2 else 0 for i in range(n) if i % 2 == 0])
	wrong1 = sum([1 if a[i] % 2 != i % 2 else 0 for i in range(n) if i % 2 == 1])
	print(wrong0 if wrong0 == wrong1 else -1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	flag = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			for j in range(i + 1, n):
				if j % 2 != a[j] % 2 and j % 2 == a[i] % 2 and (i % 2 == a[j] % 2):
					(a[i], a[j]) = (a[j], a[i])
					ans += 1
	for i in range(n):
		if i % 2 != a[i] % 2:
			flag = 1
	print(ans) if flag == 0 else print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	(e_c, o_c) = (0, 0)
	for j in range(n):
		if j % 2 == 0 and a[j] % 2 != 0:
			e_c += 1
		elif j % 2 != 0 and a[j] % 2 == 0:
			o_c += 1
	if e_c != o_c:
		print(-1)
		continue
	else:
		print(e_c)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	rest = []
	for j in range(n):
		if j % 2 != l[j] % 2:
			rest.append(j)
	(o, e) = (0, 0)
	for k in rest:
		if k % 2 == 0:
			e += 1
		else:
			o += 1
	if o == e:
		print(int(len(rest) / 2))
	else:
		print(-1)


import os
inp = os.read(0, int(10000000.0)).split()
inp_pos = -1

def cin():
	global inp_pos
	inp_pos += 1
	return inp[inp_pos]
T = int(cin())
res = []
while T:
	T -= 1
	n = int(cin())
	bad = [0, 0]
	for i in range(n):
		a = int(cin())
		if a % 2 != i % 2:
			bad[i % 2] += 1
	res.append(str(bad[0] if bad[0] == bad[1] else -1).encode())
os.write(1, '\n'.encode().join(res))


n = int(input())

def solve():
	num = int(input())
	arr = list(map(int, input().split()))
	l = False
	for i in range(len(arr)):
		if i % 2 != arr[i] % 2:
			l = True
			break
	if not l:
		print(0)
	if l:
		swaps = 0
		term = False
		for i in range(len(arr)):
			if term:
				break
			if i % 2 != arr[i] % 2:
				for j in range(len(arr)):
					if arr[i] % 2 == j % 2 and arr[j] % 2 == i % 2:
						temp = arr[i]
						arr[i] = arr[j]
						arr[j] = temp
						swaps += 1
						break
				else:
					print('-1')
					term = True
					break
		if not term:
			print(swaps)
for x in range(n):
	solve()


T = int(input())

def solve(arr):
	(a, b) = (0, 0)
	for i in range(0, len(arr)):
		if i % 2 == 1 and arr[i] % 2 == 0:
			a += 1
		if i % 2 == 0 and arr[i] % 2 == 1:
			b += 1
	if a == b:
		print(a)
	else:
		print(-1)
while T > 0:
	n = int(input())
	arr = [int(el) for el in input().split()]
	solve(arr)
	T -= 1


t = int(input())
for i in range(t):
	n = int(input())
	e = 0
	o = 0
	ev = 0
	od = 0
	lst = list(map(int, input().split()))
	for j in range(n):
		if lst[j] % 2 == 0:
			ev = ev + 1
			if j % 2 != 0:
				e = e + 1
		elif lst[j] % 2 != 0:
			od = od + 1
			if j % 2 == 0:
				o = o + 1
	y = min(e, o)
	if n % 2 != 0:
		if od > ev:
			y = -1
		elif ev != od + 1:
			y = -1
	elif od != ev:
		y = -1
	print(y)


t = int(input())
for _ in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	odd = 0
	odd = sum((1 if i % 2 == 1 else 0 for i in array))
	even = n - odd
	mis_match = 0
	for (i, val) in enumerate(array):
		if i % 2 != val % 2:
			mis_match += 1
	if n % 2 == 0 and odd != even:
		print(-1)
	elif n % 2 == 1 and even != odd + 1:
		print(-1)
	else:
		odd_values = []
		even_values = []
		for i in range(n):
			if i % 2 != array[i] % 2:
				if array[i] % 2 == 1:
					odd_values.append((array[i], i))
				else:
					even_values.append((array[i], i))
		print(len(odd_values))


for _ in range(int(input())):
	n = int(input())
	lst = [int(x) for x in input().split()]
	(zeros, ones) = (0, 0)
	for x in range(len(lst)):
		if lst[x] % 2 != x % 2:
			if lst[x] % 2 != 0:
				ones += 1
			else:
				zeros += 1
	if zeros == 0 and ones == 0:
		print(0)
	elif zeros == ones:
		print(zeros)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	counter1 = 0
	counter2 = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			counter1 += 1
		if i % 2 == 1 and a[i] % 2 == 0:
			counter2 += 1
	if counter1 != counter2:
		print(-1)
	else:
		print(counter1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	new_a = list(map(lambda x: x % 2, a))
	output = 0
	if sum(new_a) != int(n / 2):
		print(-1)
	else:
		for i in range(0, n, 2):
			output += new_a[i]
		print(output)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	a = inputlist()
	odds = 0
	evens = 0
	bad = 0
	for i in range(n):
		if a[i] % 2 == 0:
			evens += 1
		else:
			odds += 1
		if a[i] % 2 != i % 2:
			bad += 1
	if evens != odds and n % 2 == 0:
		print(-1)
		continue
	if evens - 1 != odds and n % 2 == 1:
		print(-1)
		continue
	else:
		print(bad // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	mod1 = mod2 = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 0:
				mod2 += 1
			else:
				mod1 += 1
	if mod1 == mod2:
		print(min(mod1, mod2))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even = sum((1 for num in a if num & 1 == 0))
	odd = n - even
	req_even = n // 2
	req_odd = n = req_even
	if even != req_even and req_odd != odd:
		print(-1)
		continue
	out_of_pos = sum((1 for (i, num) in enumerate(a) if num & 1 != i & 1))
	if out_of_pos & 1:
		print(-1)
		continue
	print(out_of_pos // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(ec, oc, mismc) = (0, 0, 0)
	for (i, val) in enumerate(a):
		if val % 2 == 0:
			ec += 1
		else:
			oc += 1
		if i % 2 != val % 2:
			mismc += 1
	res = 0
	if n % 2 == 0:
		if ec != oc:
			res = -1
		else:
			res = mismc / 2
	elif ec != oc + 1:
		res = -1
	else:
		res = mismc / 2
	print(int(res))


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			if arr[i] % 2 != 0:
				count1 += 1
		elif arr[i] % 2 == 0:
			count2 += 1
	if count1 == count2:
		print(count1)
	else:
		print(-1)
n = int(input())
for _ in range(n):
	main()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ch = []
	nch = []
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			ch.append(a[i])
		elif i % 2 == 1 and a[i] % 2 == 0:
			nch.append(a[i])
	if len(ch) == len(nch):
		print(len(ch))
	else:
		print(-1)


def mi():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(mi())
	(o, e) = (0, 0)
	for i in range(n):
		if i % 2:
			if a[i] % 2 == 0:
				o += 1
		elif a[i] % 2:
			e += 1
	if o == e:
		print(o)
	else:
		print(-1)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		n = int(input())
		arry = list(map(int, input().split()))
		odd = []
		even = []
		tochange = []
		for i in range(n):
			if i % 2 != arry[i] % 2:
				if i % 2:
					odd.append(i)
				else:
					even.append(i)
		z = len(odd)
		x = len(even)
		if z != x:
			yield (-1)
		else:
			yield z
t = int(input())
ans = gift()
print(*ans, sep='\n')


a = int(input())
for i in range(a):
	b = int(input())
	c = [int(j) for j in input().split(' ')[:b]]
	r1 = 0
	r2 = 0
	r3 = 0
	for k in range(len(c)):
		if k % 2 == 0 and c[k] % 2 != 0:
			r1 = r1 + 1
		elif k % 2 != 0 and c[k] % 2 == 0:
			r3 = r3 + 1
		else:
			r2 = r2 + 1
	if r1 == r3:
		print(r1)
	elif r2 == len(c):
		print(0)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	wrong_odd = 0
	wrong_even = 0
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			if i % 2 == 1:
				wrong_odd += 1
			else:
				wrong_even += 1
	if wrong_odd != wrong_even:
		print(-1)
	else:
		print(wrong_odd)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
t = intIn()
while t > 0:
	t -= 1
	n = intIn()
	a = listIn()
	(odd, even) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				odd += 1
		elif a[i] % 2 == 0:
			even += 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	e = 0
	o = 0
	if n % 2 == 0:
		e = round(n) / 2
		o = e
	else:
		e = round(n / 2 + 0.5)
		o = e - 1
	for i in range(n):
		if a[i] % 2 == 0:
			e -= 1
		else:
			o -= 1
	if e == 0 and o == 0:
		w = 0
		for i in range(n):
			if i % 2 != a[i] % 2:
				w += 1
		print(round(w / 2))
	else:
		print(-1)


import sys
q = int(sys.stdin.readline())
for _ in range(q):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	cnt1 = 0
	cnt2 = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			cnt1 += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			cnt2 += 1
	if cnt1 == cnt2:
		print(cnt1)
	else:
		print(-1)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	cnt = [0, 0]
	for i in range(n):
		if a[i] % 2 != i % 2:
			cnt[i % 2] += 1
	if cnt[0] != cnt[1]:
		print(-1)
		return
	print(cnt[0])
tn = int(input())
for _ in range(tn):
	main()


inp = int(input())
for iter in range(inp):
	inp1 = int(input())
	l = input().split()
	counter = 0
	if inp1 == 1:
		if int(l[0]) % 2 != 0:
			counter = -1
		else:
			counter = 0
	else:
		for x in range(0, len(l)):
			if x % 2 == 0 and int(l[x]) % 2 != 0:
				temp = int(l[x])
				for num in range(x + 1, len(l)):
					if int(l[num]) % 2 == 0 and num % 2 != 0:
						l[x] = l[num]
						l[num] = temp
						counter += 1
						break
				else:
					counter = -1
					break
			elif x % 2 != 0 and int(l[x]) % 2 == 0:
				temp = int(l[x])
				for num in range(x + 1, len(l)):
					if int(l[num]) % 2 != 0 and num % 2 == 0:
						l[x] = l[num]
						l[num] = temp
						counter += 1
						break
				else:
					counter = -1
					break
	print(counter)


T = int(input())

def swap(change_arr, arr):
	return (change_arr, arr)

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	even_count = 0
	odd_count = 0
	for i in range(len(arr)):
		if arr[i] % 2 == 0:
			arr[i] = 0
			even_count += 1
		else:
			arr[i] = 1
			odd_count += 1
	if even_count != odd_count:
		if even_count != odd_count + 1:
			return -1
	model_arr = [0] * n
	for i in range(1, len(arr), 2):
		model_arr[i] = 1
	if model_arr == arr:
		return 0
	count = 0
	for i in range(n):
		if arr[i] != model_arr[i]:
			count += 1
	return count // 2
for i in range(T):
	print(main())


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().rstrip().split()))
	(c, flag) = (0, 0)
	for i in range(n):
		if i % 2 != l[i] % 2:
			for j in range(n):
				if j % 2 != l[j] % 2 and l[j] % 2 == i % 2:
					(l[i], l[j]) = (l[j], l[i])
					c += 1
					break
	for i in range(n):
		if i % 2 == l[i] % 2:
			flag += 1
	if flag == n:
		print(c)
	else:
		print(-1)


test_case = int(input())
for i in range(test_case):
	o = 0
	e = 0
	length = int(input())
	values = list(map(int, input().split(' ')))
	for k in range(length):
		if k % 2 == 0:
			if values[k] % 2 == 0:
				continue
			else:
				o += 1
		elif values[k] % 2 == 1:
			continue
		else:
			e += 1
	if o == e:
		print(o)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	lis = [int(x) for x in input().split()]
	suma = 0
	sumb = 0
	for i in range(len(lis)):
		if i % 2 == lis[i] % 2:
			pass
		elif lis[i] % 2 == 0:
			suma += 1
		else:
			sumb += 1
	if suma != sumb:
		print(-1)
	else:
		print(suma)


from sys import stdin, stdout
from collections import Counter
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	a = [a[i] % 2 for i in range(n)]
	cnt = 0
	ones = Counter(a)[1]
	if len(a) // 2 != ones:
		stdout.write('-1\n')
	else:
		for i in range(n):
			if i % 2 == 0 and a[i] == 1:
				cnt += 1
		stdout.write(str(cnt) + '\n')


def solve():
	t = int(input())
	for i in range(t):
		n = int(input())
		m = [int(s) for s in input().split()]
		ch = [0, 0]
		for j in range(n):
			if m[j] % 2 != j % 2:
				ch[m[j] % 2] += 1
		if ch[0] == ch[1]:
			print(ch[0])
		else:
			print(-1)
solve()


for test_case in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(c0, f, c1) = (0, 1, 0)
	for i in range(n):
		if f:
			f = 0
		else:
			f = 1
		if a[i] % 2 != f:
			if f == 0:
				c0 += 1
			else:
				c1 += 1
	if c1 == 0 and c0 == 0:
		print(0)
	elif c1 == c0:
		print(c1)
	else:
		print(-1)


t = int(input())
for i in range(t):
	num = int(input())
	even = 0
	odd = 0
	if num % 2 == 1:
		indexe = (num + 1) // 2
		indexo = num - indexe
	else:
		indexe = num // 2
		indexo = num // 2
	arr = [0] * num
	arr = input().split()
	different = 0
	for k in range(num):
		arr[k] = int(arr[k])
		if arr[k] % 2 == 0:
			even += 1
		else:
			odd += 1
		if k % 2 == 0 and arr[k] % 2 == 1:
			different += 1
		if k % 2 == 1 and arr[k] % 2 == 0:
			different += 1
	if even != indexe or odd != indexo:
		print(-1)
	else:
		print(different // 2)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	(o, e) = (0, 0)
	for (i, num) in enumerate(l):
		if i % 2 == 0:
			if num % 2 != 0:
				o += 1
		elif num % 2 == 0:
			e += 1
	if o == e:
		print(o)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	odisplaced = 0
	edisplaced = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if i % 2:
				odisplaced += 1
			else:
				edisplaced += 1
	if odisplaced != edisplaced:
		print(-1)
	else:
		print(odisplaced)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	od = 0
	ev = 0
	for i in range(n):
		if a[i] % 2 == i % 2:
			continue
		elif i % 2 == 0:
			ev += 1
		else:
			od += 1
	if od == ev:
		print(od)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	count1 = 0
	count2 = 0
	for i in range(n):
		if i % 2 == 0 and list1[i] % 2 != 0:
			count1 += 1
		if i % 2 != 0 and list1[i] % 2 == 0:
			count2 += 1
	if count1 == count2:
		print(count1)
	else:
		print(-1)


test = int(input())
while test != 0:
	n = int(input())
	l = list(map(int, input().split()))
	cnt = 0
	even = 0
	odd = 0
	for i in range(len(l)):
		if i % 2 != l[i] % 2:
			cnt += 1
			if l[i] % 2 == 0:
				even += 1
			else:
				odd += 1
	if cnt == 0:
		print(0)
	elif cnt % 2 == 1:
		print(-1)
	elif even == odd:
		print(cnt // 2)
	else:
		print(-1)
	test -= 1


def array(arr, struc):
	return list(map(struc, arr.split()))
n = int(input())
while n:
	lena = int(input())
	arr = array(input(), int)
	parity = [0] * 2
	counter = 0
	for i in range(lena):
		modi = i % 2
		arri = arr[i] % 2
		parity[arri] += 1
		if modi != arri:
			counter += 1
	if counter > 0:
		odd = lena // 2
		if odd == parity[1]:
			print(counter // 2)
		else:
			print(-1)
	else:
		print(0)
	n -= 1


n = int(input())

def calc(x, a):
	arr = []
	for i in range(x):
		if a[i] % 2 == 0:
			arr.append(0)
		else:
			arr.append(1)
	o = arr.count(1)
	if x // 2 != o:
		print(-1)
	else:
		c = 0
		for i in range(0, x, 2):
			if arr[i] != 0:
				c = c + 1
		print(c)
for i in range(n):
	x = int(input())
	a = list(map(int, input().split()))
	calc(x, a)


def solve(arr, n, ans):
	moves = 0
	for i in range(n):
		if arr[i] % 2 != i % 2:
			index = -1
			for j in range(i, n):
				if arr[j] % 2 != j % 2 and arr[i] % 2 == j % 2 and (arr[j] % 2 == i % 2):
					index = j
					break
			if index == -1:
				ans.append(-1)
				return
			(arr[i], arr[j]) = (arr[j], arr[i])
			moves += 1
	ans.append(moves)

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		solve(arr, n, ans)
	for i in ans:
		print(i)
main()


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().strip(' ').split(' ')))
	wrong_zero = 0
	wrong_one = 0
	for i in range(0, n):
		temp = arr[i] % 2
		if i % 2 == 0:
			if temp == 1:
				wrong_one += 1
		elif temp == 0:
			wrong_zero += 1
	if wrong_zero == 0 and wrong_one == 0:
		print(0)
	elif wrong_one == wrong_zero:
		print(wrong_zero)
	else:
		print(-1)


for _ in range(int(input())):
	input()
	l = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(len(l)):
		if l[i] % 2 != i % 2:
			if i % 2 == 0:
				e += 1
			else:
				o += 1
	print(-1 if e != o else e)


t = int(input())
for i in range(t):
	n = int(input())
	ar = [int(i) for i in input().split()]
	gud = 0
	bad = 0
	for j in range(n):
		if j % 2 == ar[j] % 2:
			pass
		elif j % 2 == 1 and ar[j] % 2 == 0:
			gud += 1
		else:
			bad += 1
	if gud == bad:
		print(gud)
	else:
		print(-1)


def read_int():
	n = int(input())
	return n

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints

def solve(n, a):
	wrong_odds = 0
	wrong_evens = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				wrong_evens += 1
		elif a[i] % 2 == 0:
			wrong_odds += 1
	if wrong_odds != wrong_evens:
		return -1
	return wrong_odds
t = read_int()
for case in range(t):
	n = read_int()
	a = read_ints()
	sol = solve(n, a)
	print(sol)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	f = [-1 for i in range(n)]
	for i in range(n):
		if i % 2 != a[i] % 2:
			f[i] = i % 2
	one = f.count(1)
	zero = f.count(0)
	if one == zero:
		print(one)
	else:
		print(-1)


import math
import sys
from sys import stdin
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = [int(j) for j in input().split()]
	for i in range(n):
		arr[i] = arr[i] % 2
	count1 = arr.count(1)
	count0 = arr.count(0)
	if n % 2 == 0 and count0 != count1 or (n % 2 == 1 and count0 - 1 != count1):
		print(-1)
	elif n % 2 == 0:
		wrong = 0
		for i in range(n):
			if i % 2 != arr[i]:
				wrong += 1
		print(wrong // 2)
	else:
		wrong1 = 0
		wrong0 = 0
		for i in range(n):
			if i % 2 != arr[i]:
				if i % 2 == 0:
					wrong0 += 1
				else:
					wrong1 += 1
		print(wrong1)


t = int(input())

def simba(n, z):
	c1 = 0
	c2 = 0
	for i in range(n):
		if i % 2 == 0 and z[i] % 2 == 1:
			c1 += 1
		elif i % 2 == 1 and z[i] % 2 == 0:
			c2 += 1
	if c1 != c2:
		print(-1)
	else:
		print(c1)
for i in range(t):
	n = int(input())
	z = list(map(int, input().split()))
	simba(n, z)


def sol(a, n):
	even = 0
	odd = 0
	for (i, val) in enumerate(a):
		if val % 2 != 0 and i % 2 == 0:
			even += 1
		elif val % 2 == 0 and i % 2 != 0:
			odd += 1
	if even != odd:
		return -1
	else:
		return even
tc = int(input())
while tc:
	n = int(input())
	a = list(map(int, input().split()))
	print(sol(a, n))
	tc -= 1


import math
t = int(input())
for _ in range(0, t):
	n = int(input())
	nums = [int(i) % 2 for i in input().split()]
	if nums.count(0) != math.ceil(n / 2) or nums.count(1) != n - math.ceil(n / 2):
		print(-1)
	else:
		x = 0
		for i in range(0, n):
			if i % 2 != nums[i] % 2:
				x += 1
		print(x // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ok = 0
	nok = 0
	for i in range(n):
		if a[i] % 2 != i % 2 and a[i] % 2 == 1:
			ok += 1
		if a[i] % 2 != i % 2 and a[i] % 2 == 0:
			nok += 1
	if ok == nok:
		print(ok)
	else:
		print(-1)


t = int(input())
for k in range(t):
	num = int(input())
	arr = list(map(int, input().split(' ')))
	(npip, npii, niip, niii) = (0, 0, 0, 0)
	for (i, num) in enumerate(arr):
		if i % 2 == 0 and num % 2 == 0:
			npip += 1
		elif i % 2 == 0 and num % 2 == 1:
			niip += 1
		elif i % 2 == 1 and num % 2 == 0:
			npii += 1
		elif i % 2 == 1 and num % 2 == 1:
			niii += 1
	if niip == npii and niip > 0:
		print(niip)
	elif niip == npii and niip == 0:
		print(0)
	else:
		print(-1)


def chtotam(a):
	chelem = 0
	nechelem = 0
	for i in range(len(a)):
		if i % 2 == 0 and a[i] % 2 != 0:
			nechelem += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			chelem += 1
	if nechelem == chelem and chelem != 0:
		return chelem
	elif nechelem == chelem == 0:
		return 0
	else:
		return -1
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(chtotam(a))


T = int(input().strip())
for t in range(T):
	n = int(input().strip())
	arr = input().strip().split()
	arr = [int(x) for x in arr]
	assert len(arr) == n
	odd_parity = 0
	even_parity = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			even_parity += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			odd_parity += 1
	if odd_parity != even_parity:
		print('-1')
	else:
		print(odd_parity)


t = int(input())
while t > 0:
	n = int(input())
	li = [int(i) for i in input().split()]
	(e, o) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and li[i] % 2 != 0:
			e += 1
		elif i % 2 != 0 and li[i] % 2 == 0:
			o += 1
	if e == o:
		print(e)
	else:
		print(-1)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(displacedOdd, displacedEven) = (0, 0)
	for i in range(len(arr)):
		if i % 2 == 0 and arr[i] % 2 == 1:
			displacedOdd += 1
		elif i % 2 == 1 and arr[i] % 2 == 0:
			displacedEven += 1
	if displacedEven != displacedOdd:
		print(-1)
	else:
		print(displacedOdd)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	count_of_chet = 0
	count_of_nechet = 0
	count_of_nesovpad = 0
	for j in range(n):
		if arr[j] % 2 == 0:
			count_of_chet += 1
		else:
			count_of_nechet += 1
		if arr[j] % 2 == j % 2:
			continue
		else:
			count_of_nesovpad += 1
	if count_of_nesovpad == 0:
		print(0)
	elif n % 2 == 0:
		if count_of_nechet == count_of_chet:
			print(count_of_nesovpad // 2)
		else:
			print(-1)
	elif count_of_chet - count_of_nechet == 1:
		print(count_of_nesovpad // 2)
	else:
		print(-1)


n = int(input())
for i in range(n):
	m = int(input())
	a = list(map(int, input().split()))
	n1 = 0
	n2 = 0
	for j in range(m):
		if a[j] % 2 == 0 and j % 2 == 1:
			n1 = n1 + 1
		if a[j] % 2 == 1 and j % 2 == 0:
			n2 = n2 + 1
	if n1 != n2:
		print(-1)
	else:
		print(n1)


def solve():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	wrongP = 0
	wrongI = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				wrongP += 1
			else:
				wrongI += 1
	if wrongI == 0 and wrongP == 0:
		return 0
	if wrongI != wrongP:
		return -1
	return wrongI
n = int(input())
for i in range(n):
	print(solve())


import sys
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
t = inp()
for _ in range(t):
	n = inp()
	a = inpl()
	o = e = 0
	for (i, x) in enumerate(a):
		if i % 2 != x % 2:
			if i % 2:
				o += 1
			else:
				e += 1
	print(o if o == e else -1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	mod = []
	swaps_o = 0
	swaps_e = 0
	for i in range(n):
		if a[i] % 2 == 1 and i & 1 == 0:
			swaps_o += 1
		elif a[i] % 2 == 0 and i & 1 == 1:
			swaps_e += 1
	if swaps_o == swaps_e:
		print(swaps_o)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	co = 0
	ce = 0
	for i in range(n):
		if i % 2 == 1:
			if a[i] % 2 == 0:
				ce += 1
		elif i % 2 == 0:
			if a[i] % 2 != 0:
				co += 1
	if co == ce:
		print(co)
	else:
		print('-1')


t = int(input())
mass = []
for i in range(t):
	n = int(input())
	ar = input().split(' ')
	ar = [int(x) for x in ar]
	mass.append(ar)
for ar in mass:
	valid = 1
	answer = 0
	for i in range(len(ar)):
		if ar[i] % 2 != i % 2:
			j = i + 1
			for j in range(i + 1, len(ar), 2):
				if ar[j] % 2 != j % 2:
					answer += 1
					(ar[i], ar[j]) = (ar[j], ar[i])
					break
			else:
				print('-1')
				break
	else:
		print(answer)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	ce = 0
	co = 0
	for i in range(len(arr)):
		if i % 2 == 0 and arr[i] % 2 == 1:
			ce += 1
		elif i % 2 == 1 and arr[i] % 2 == 0:
			co += 1
	if ce == co:
		print(ce)
	else:
		print(-1)


for xyz in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	oae = 0
	eao = 0
	for i in range(0, n):
		if i % 2 != l[i] % 2:
			if i % 2 == 0:
				oae += 1
			else:
				eao += 1
	if eao == oae:
		print(eao)
	else:
		print(-1)


a = int(input())
for i in range(0, a):
	n = int(input())
	arr = list(map(int, input().split()))
	e = 0
	o = 0
	for j in range(0, len(arr)):
		if j % 2 == 0 and arr[j] % 2 != 0:
			e = e + 1
		if j % 2 != 0 and arr[j] % 2 == 0:
			o = o + 1
	if e == o:
		print(e)
	else:
		print(-1)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	y = 0
	for i in range(0, n):
		if i % 2 == 0 and a[i] % 2 == 1:
			x += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			y += 1
	if x != y:
		print(-1)
	else:
		print(x)
t = int(input())
for tt in range(0, t):
	solve()


for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	r = 0
	(o, e) = (0, 0)
	for j in range(a):
		if b[j] % 2 == 0:
			e += 1
		if b[j] % 2 == 1:
			o += 1
		if j % 2 != b[j] % 2:
			r += 1
	if a % 2 == 0:
		if e == a // 2 and o == a // 2 and (r % 2 == 0):
			print(r // 2)
		else:
			print(-1)
	elif o == a // 2 and e == (a + 1) // 2 and (r % 2 == 0):
		print(r // 2)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	cnt_e = 0
	cnt_o = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			cnt_o += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			cnt_e += 1
	if cnt_o == cnt_e:
		print(cnt_e)
	else:
		print(-1)


def dhana(l, a):
	e = 0
	o = 0
	for i in range(a):
		x = i % 2
		y = l[i] % 2
		if x != y:
			if l[i] % 2 == 0:
				e += 1
			else:
				o += 1
	if o == e:
		return o
	return -1
n = int(input())
for i in range(n):
	a = int(input())
	l = [int(j) for j in input().split()]
	x = dhana(l, a)
	print(x)


def convert(arr):
	conv = []
	for i in arr:
		j = i % 2
		conv.append(j)
	return conv
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	conv = convert(arr)
	n0 = conv.count(0)
	n1 = conv.count(1)
	if n % 2 == 0:
		num0 = n // 2
		num1 = n // 2
	else:
		num0 = n // 2 + 1
		num1 = n // 2
	if n0 == num0 and n1 == num1:
		req = []
		for i in range(n):
			j = i % 2
			req.append(j)
		count = 0
		for i in range(n):
			if conv[i] != req[i]:
				count += 1
		print(count // 2)
	else:
		print(-1)


for _ in range(int(input())):
	c = 0
	d = 0
	i = 0
	j = 1
	n = int(input())
	s = list(input().split())
	if len(s) > 1:
		for i in s:
			if int(i) % 2 != 0:
				c += 1 * j
			if int(i) % 2 == 0:
				d += 1 * (1 - j)
			j = 1 - j
		if c == d:
			print(c)
		else:
			print('-1')
	else:
		print(c if int(s[0]) % 2 == 0 else -1)


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	x = [0, 0]
	for i in range(n):
		if array[i] & 1 != i & 1:
			x[i & 1] += 1
	print(-1 if x[0] != x[1] else x[0])


def get_ans(n, arr):
	ch = 0
	np = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			ch += 1
		if arr[i] % 2 != i % 2:
			np += 1
	nch = n - ch
	if ch == nch or ch == nch + 1:
		pass
	else:
		return -1
	if np % 2 == 1:
		return -1
	else:
		return np // 2
t = int(input())
anss = []
for _ in range(t):
	q = int(input())
	st = input().split(' ')
	st = list(map(int, st))
	anss.append(get_ans(q, st))
for i in anss:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c1 = c2 = c3 = s = 0
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] % 2 == 1:
				c1 += 1
		elif l[i] % 2 == 0:
			c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)


t = int(input())
while t != 0:
	t = t - 1
	a = []
	b = []
	d = []
	w = 0
	n = int(input())
	n1 = 2 * n - 1
	c = input()
	c = c.ljust(len(c) + 1)
	for i in range(0, c.count(' ')):
		a.append(int(c[0:c.find(' ')]))
		c = c[c.find(' ') + 1:len(c)]
	for i in range(0, n):
		if a[i] % 2 == i % 2:
			b.append(0)
			d.append(0)
		else:
			b.append(1)
			if i % 2 == 1:
				d.append(1)
			else:
				d.append(2)
			w = w + 1
	if b.count(1) == 0:
		print('0')
	elif b.count(1) % 2 == 1 or d.count(1) != d.count(2):
		print('-1')
	else:
		print(int(w / 2))


t = int(input())
for row in range(t):
	n = int(input())
	mas = [int(i) for i in input().split()]
	j = 0
	even_i = 0
	even_el = 0
	odd_i = 0
	odd_el = 0
	for i in range(len(mas)):
		if i % 2 != mas[i] % 2:
			if i % 2:
				odd_i += 1
			else:
				even_i += 1
			if mas[i] % 2:
				odd_el += 1
			else:
				even_el += 1
	if even_i == odd_i:
		print(even_i)
	else:
		print(-1)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	(count_even, count_odd) = (0, 0)
	for i in a:
		if i % 2 == 0:
			count_even += 1
		else:
			count_odd += 1
	if n % 2 == 0:
		(c_e, c_o) = (n // 2, n // 2)
	else:
		(c_e, c_o) = (n // 2 + 1, n // 2)
	if count_even != c_e or count_odd != c_o:
		print(-1)
	else:
		c = 0
		for i in range(n):
			if i % 2 != a[i] % 2:
				c += 1
		print(c // 2)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ab = ''
	bc = ''
	(evenr, oddr) = (0, 0)
	if n % 2 == 0:
		evenp = n // 2
		oddp = n // 2
		ab = '01' * oddp
	else:
		evenp = n // 2 + 1
		oddp = n // 2
		ab = '01' * oddp + '0'
	for i in range(n):
		if arr[i] % 2 == 0:
			evenr += 1
			bc += '0'
		else:
			oddr += 1
			bc += '1'
	if oddr > oddp or evenr > evenp:
		print(-1)
	else:
		print(bin(int(ab, 2) ^ int(bc, 2)).count('1') // 2)


t = int(input())
for test in range(0, t):
	n = int(input())
	oae = eao = 0
	ar = input().split()
	for i in range(0, n):
		if i % 2 == 0:
			if int(ar[i]) % 2 == 1:
				oae += 1
		elif int(ar[i]) % 2 == 0:
			eao += 1
	if eao == oae:
		print(eao)
	else:
		print(-1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(l()[0]):
	n = l()[0]
	A = l()
	B = [A[i] % 2 == i % 2 for i in range(n)]
	if False not in B:
		print(0)
		continue
	if B.count(False) % 2:
		print(-1)
		continue
	count = 0
	for i in range(n):
		if B[i]:
			continue
		for j in range(i + 1, n):
			if B[j]:
				continue
			if A[i] % 2 == j % 2 and A[j] % 2 == i % 2:
				count += 1
				(A[i], A[j]) = (A[j], A[i])
				B[i] = True
				B[j] = True
				break
		if B[i] == False:
			break
	if False in B:
		print(-1)
	else:
		print(count)


def resolve(numbs):
	count = 0
	for i in range(len(numbs)):
		if i % 2 != numbs[i] % 2:
			count += 1
	return count // 2
tests = int(input())
for _ in range(tests):
	n = int(input())
	numbs = list(map(int, input().split()))
	odd = []
	even = []
	for i in range(len(numbs)):
		if numbs[i] % 2 == 0:
			even.append(numbs[i])
		else:
			odd.append(numbs[i])
	if n % 2 == 0:
		if len(even) != len(odd):
			print(-1)
		else:
			print(resolve(numbs))
	elif len(even) <= len(odd):
		print(-1)
	elif len(even) - 1 == len(odd):
		print(resolve(numbs))
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	l2 = []
	for i in range(n):
		if l[i] % 2 == 0:
			l2.append(i)
		else:
			l1.append(i)
	s1 = 0
	s2 = 0
	for i in l2:
		if i % 2 != 0:
			s2 = s2 + 1
	for i in l1:
		if i % 2 != 1:
			s1 = s1 + 1
	if s2 == s1:
		print(s2)
	else:
		print('-1')


t = int(input())
for ij in range(t):
	n = int(input())
	arr = [int(x) % 2 for x in input().split()]
	for i in range(n):
		if i % 2 != arr[i]:
			arr[i] = 1
		else:
			arr[i] = 0
	epc = 0
	opc = 0
	for i in range(n):
		if arr[i] == 1:
			if i % 2 == 0:
				epc += 1
			else:
				opc += 1
	if epc == 0 and opc == 0:
		print(0)
	elif epc != opc:
		print(-1)
	else:
		print(epc)


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	chet = (a + 1) // 2
	nechet = a // 2
	ss = 0
	for i in range(a):
		if b[i] % 2 == 0:
			chet -= 1
		else:
			nechet -= 1
		if b[i] % 2 == i % 2:
			ss += 1
	if chet == nechet == 0:
		print((a - ss) // 2)
	else:
		print(-1)


t1 = int(input())
for i in range(t1):
	n = int(input())
	l = 0
	p = 0
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] % 2 == 0 and i % 2 == 1:
			l += 1
		if a[i] % 2 == 1 and i % 2 == 0:
			p += 1
	if l == p:
		print(p)
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 == 0:
		cnte = 0
		for i in range(len(a)):
			if a[i] % 2 == 0:
				cnte = cnte + 1
		if cnte != len(a) // 2:
			print('-1')
		else:
			cnt = 0
			i = 0
			while i < len(a):
				if a[i] % 2 != 0:
					cnt = cnt + 1
				i = i + 2
			print(cnt)
	else:
		cnte = 0
		for i in range(len(a)):
			if a[i] % 2 == 0:
				cnte = cnte + 1
		if cnte != len(a) // 2 + 1:
			print('-1')
		else:
			cnt = 0
			i = 0
			while i < n:
				if a[i] % 2 != 0:
					cnt = cnt + 1
				i = i + 2
			print(cnt)
	t = t - 1


for i in range(int(input())):
	even = 0
	odd = 0
	input()
	a = [int(i) % 2 for i in input().split()]
	for i in range(len(a)):
		if i % 2 == 0:
			if a[i] % 2 == 1:
				even += 1
		elif a[i] % 2 == 0:
			odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


n = int(input())

def evenarray(l, a):
	cnte = 0
	cnto = 0
	for i in l:
		if i % 2 == 0:
			cnte += 1
		else:
			cnto += 1
	if a % 2 == 0:
		if cnte != cnto:
			return -1
	elif cnte - 1 != cnto:
		return -1
	cnt = 0
	for i in range(a):
		if i % 2 == 0 and l[i] % 2 == 1:
			cnt += 1
	return cnt
l = []
for i in range(n):
	a = int(input())
	l.append(list(map(int, input().split(' '))))
for i in l:
	b = len(i)
	print(evenarray(i, b))


for _ in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	if sum((i & 1 for i in a)) != n >> 1:
		print(-1)
		continue
	print(sum((i & 1 != a[i] & 1 for i in range(len(a)))) >> 1)


t = int(input())
for _ in range(t):
	n = int(input())
	inp = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(len(inp)):
		if inp[i] & 1 != i & 1:
			if i & 1:
				even += 1
			else:
				odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	(even, odd) = (0, 0)
	nums = map(int, input().split())
	for (i, n) in enumerate(nums):
		if i & 1 == 0:
			if n & 1:
				even += 1
		elif n & 1 == 0:
			odd += 1
	print(even if even == odd else -1)


import os
import sys

def get_int():
	return int(input())

def get_ints():
	return map(int, input().split())

def get_strs():
	return input().split()

def get_float():
	return float(input())

def get_floats():
	return map(float, input().split())

def list_strs():
	return list(input().split())

def list_ints():
	return list(map(int, input().split()))

def list_floats():
	return list(map(float, input.split()))

def post(x):
	print(x, end=' ')
T = int(input())
for t in range(1, T + 1):
	n = get_int()
	arr = list_ints()
	(e, o) = ([], [])
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 == 1:
			e.append(arr[i])
		if i % 2 == 1 and arr[i] % 2 == 0:
			o.append(arr[i])
	print(-1 if len(e) != len(o) else len(o))


t = int(input())
even = []
odd = []
j = 0
while t:
	n = int(input())
	ar = list(map(int, input().split()))
	for i in ar:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	i = 0
	if abs(len(even) - len(odd)) >= 2:
		print(-1)
	elif abs(len(even) - len(odd)) == 0:
		for i in range(len(ar)):
			if i % 2 != ar[i] % 2:
				j = j + 1
		print(int(j / 2))
	elif len(even) > len(odd):
		for i in range(len(ar)):
			if i % 2 != ar[i] % 2:
				j = j + 1
		print(int(j / 2))
	else:
		print(-1)
	even = []
	odd = []
	j = 0
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	odd = []
	even = []
	for i in range(n):
		if i % 2 == ar[i] % 2:
			pass
		elif i % 2:
			odd.append(i)
		else:
			even.append(i)
	if len(odd) == len(even):
		print(len(odd))
	else:
		print(-1)


import sys
import heapq
import random
import collections

def solve(lst):
	console('----- solving ------')
	lst = [(i % 2, x % 2) for (i, x) in enumerate(lst) if i % 2 != x % 2]
	c = collections.Counter(lst)
	if c[0, 1] == c[1, 0]:
		return c[0, 1]
	return -1

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	_ = input()
	lst = list(map(int, input().split()))
	res = solve(lst)
	print(res)


TC = int(input())
for t_itr in range(TC):
	N = int(input())
	D = list(map(int, input().split()))
	odd_count = 0
	even_count = 0
	for (i, d) in enumerate(D):
		if d % 2 == 0 and i % 2 != 0:
			even_count += 1
		if d % 2 != 0 and i % 2 == 0:
			odd_count += 1
	if even_count == odd_count:
		print(odd_count)
	else:
		print(-1)


t = int(input())
for z in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	e = o = 0
	for i in l:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
	if o != int(n / 2):
		print(-1)
	else:
		c = 0
		for i in range(0, n):
			if l[i] % 2 != i % 2:
				c += 1
		print(int(c / 2))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	m = input().split()
	a = [int(i) for i in m]
	b = 0
	c = 0
	for i in range(0, len(a)):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				b += 1
			else:
				c += 1
	if c != b:
		print(-1)
	else:
		print(c)


n = input()
for i in range(int(n)):
	m = int(input())
	c = list(map(int, input().strip().split()))
	(odd, even) = ([], [])
	for i in range(len(c)):
		if c[i] % 2 == 0 and i % 2 != 0:
			odd.append(i)
		if c[i] % 2 != 0 and i % 2 == 0:
			even.append(i)
	if len(odd) == len(even):
		print(len(odd))
	if len(odd) != len(even):
		print(-1)


import sys, os
import math
from fractions import Fraction
from collections import defaultdict

def linput():
	return list(minput())

def minput():
	return map(int, sys.stdin.readline().strip().split())
t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	a = linput()
	(e1, e2, o) = (0, 0, 0)
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				e1 += 1
			else:
				e2 += 1
	if e1 == e2:
		print(e1)
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	o = 0
	d = 0
	for (i, x) in enumerate(a):
		o += x % 2
		d += (x - i) % 2
	if o == n // 2:
		print(d // 2)
	else:
		print(-1)


try:
	t = int(input())
	while t:
		n = int(input())
		l = [int(x) for x in input().split()]
		if n == 1:
			if l[0] % 2 == 0:
				print('0')
			else:
				print('-1')
		else:
			eve = 0
			odd = 0
			for i in range(n):
				a = i % 2
				b = l[i] % 2
				if a == b:
					pass
				if a != b and a == 0:
					eve += 1
				if a != b and a == 1:
					odd += 1
			if eve == odd:
				print(eve)
			else:
				print('-1')
		t -= 1
except:
	pass


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(odds, evens) = (0, 0)
	for i in range(0, n, 2):
		if arr[i] % 2 == 0:
			continue
		evens += 1
	for i in range(1, n, 2):
		if arr[i] % 2 == 1:
			continue
		odds += 1
	if odds == evens:
		print(evens)
	else:
		print(-1)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		e2o = o2e = 0
		for (c, el) in enumerate(a):
			if c % 2 == 0 and el % 2 != 0:
				o2e += 1
			elif c % 2 != 0 and el % 2 == 0:
				e2o += 1
		if e2o != o2e:
			print(-1)
		else:
			print(e2o)
main()


for i in range(int(input())):
	input()
	cnt = [0] * 2
	lst = list(map(int, input().split()))
	for (j, p) in enumerate(lst):
		cnt[j & 1] += j & 1 != p & 1
	print(cnt[0] if cnt[0] == cnt[1] else -1)


m = int(input())
for k in range(m):
	n = int(input())
	l = list(map(int, input().split()))
	(a, b) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				a = a + 1
		elif l[i] % 2 != 1:
			b = b + 1
	if a == b:
		print(a)
	else:
		print(-1)


t = int(input())
for q in range(t):
	n = int(input())
	ch = input()
	L = [int(i) for i in ch.split()]
	nbp = 0
	nbi = 0
	for i in range(n):
		if L[i] % 2 != i % 2:
			if i % 2 == 0:
				nbp += 1
			else:
				nbi += 1
	if nbp != nbi:
		print(-1)
	else:
		print(nbp)


def answer(n, A):
	count = 0
	for i in A:
		if i % 2 == 0:
			count += 1
	if n % 2 == 0:
		if count != n // 2:
			return -1
	if n % 2 != 0:
		if count != n // 2 + 1:
			return -1
	count = 0
	for i in range(n):
		if i % 2 == 0:
			if A[i] % 2 != 0:
				count += 1
		elif A[i] % 2 == 0:
			count += 1
	return count // 2
t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	print(answer(n, A))


t = int(input())
for i in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	c = 0
	e = 0
	o = 0
	for i in range(n):
		if ar[i] % 2 != i % 2:
			c += 1
			if ar[i] % 2 == 0:
				e += 1
			else:
				o += 1
	if e == o:
		print(e)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 != 0 or (i % 2 != 0 and l[i] % 2 == 0):
			if l[i] % 2 == 0:
				even = even + 1
			else:
				odd = odd + 1
			c = c + 1
	if c % 2 == 0 and odd == even:
		print(c // 2)
	else:
		print(-1)


def check(n, a):
	c = 0
	d = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			c += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			d += 1
	if c == d:
		print(d)
	else:
		print(-1)
t = int(input())
for i in range(1, t + 1):
	n = int(input())
	a = list(map(int, input().split()))
	check(n, a)


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(int(input())):
	n = inin()
	l = ain()
	e = E = O = 0
	f = o = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			f = 1
			if i % 2 == 0:
				e += 1
			if l[i] % 2 == 0:
				E += 1
			else:
				O += 1
			if i % 2 == 1:
				o += 1
	if f == 1:
		if o == O and e == E:
			print((o + e) // 2)
		else:
			print(-1)
	else:
		print(0)


def solve():
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().strip().split()))
		(o, e) = (0, 0)
		for i in range(n):
			if i % 2 == l[i] % 2:
				continue
			elif i % 2 == 0:
				e += 1
			else:
				o += 1
		if e == o:
			print(e)
		else:
			print(-1)
solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	vals = list(map(int, input().split()))
	weven = 0
	wodd = 0
	for s in range(n):
		if s % 2 != vals[s] % 2:
			if vals[s] % 2 == 0:
				weven += 1
			else:
				wodd += 1
	if weven == wodd:
		print(weven)
	else:
		print(-1)


for _ in range(int(input())):
	even = 0
	odd = 0
	n = int(input())
	s = list(map(int, input().split()))
	counter = 0
	for (index, value) in enumerate(s):
		if index % 2 == 0 and value % 2 != 0:
			even += 1
		elif index % 2 != 0 and value % 2 == 0:
			odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


n = int(input())
for i in range(n):
	temp = input()
	lst = list(map(int, input().split()))
	(ans, even, odd) = (0, 0, 0)
	for j in range(len(lst)):
		if j % 2 != lst[j] % 2:
			if lst[j] % 2 == 1:
				odd += 1
			else:
				even += 1
			ans += 1
	if even != odd:
		print(-1)
	else:
		print(ans // 2)


n = int(input())
for _ in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	wc = [0, 0]
	for i in range(m):
		if l[i] % 2 != i % 2:
			wc[i % 2] += 1
	print(-1 if wc[0] != wc[1] else wc[0])


for _ in range(int(input())):
	n = int(input())
	even_count_array = 0
	odd_count_array = 0
	for i in range(n):
		if i % 2 == 1:
			odd_count_array += 1
		else:
			even_count_array += 1
	arr = [int(i) for i in input().split()]
	even_count = 0
	odd_count = 0
	discrepancies = 0
	for i in range(len(arr)):
		if arr[i] % 2 == 0:
			even_count += 1
		else:
			odd_count += 1
		if arr[i] % 2 != i % 2:
			discrepancies += 1
	if odd_count != odd_count_array or even_count != even_count_array:
		print(-1)
		continue
	else:
		print(discrepancies // 2)


for t in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	l = []
	for i in x:
		l.append(i % 2)
	i = 0
	j = 1
	count = 0
	flag = False
	while i < n:
		if i % 2 == l[i]:
			i += 1
			j = i + 1
		else:
			flag = True
			while j < n:
				if l[j] != j % 2 and l[j] != l[i]:
					(l[j], l[i]) = (l[i], l[j])
					count += 1
					i += 1
					flag = False
					break
				j += 1
			if flag:
				print(-1)
				break
	if not flag:
		print(count)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	ans = []
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 == 0 or (i % 2 != 0 and l[i] % 2 != 0):
			ans.append(0)
		elif i % 2 == 0 and l[i] % 2 != 0:
			ans.append(1)
		else:
			ans.append(-1)
	a = ans.count(0)
	b = ans.count(1)
	c = ans.count(-1)
	if a == n:
		print(0)
	elif b == c:
		print(b)
	else:
		print('-1')
	t -= 1


t = int(input())
while t:
	t -= 1
	n = int(input())
	(a, b) = (0, 0)
	s = input().split()
	l = list(map(int, s))
	for i in range(0, n):
		if i % 2 != l[i] % 2:
			if i % 2 == 0:
				a += 1
			else:
				b += 1
	if a == b:
		print(a)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	en = {False: 0, True: 0}
	l = map(int, input().split())
	for (i, x) in enumerate(l):
		en[i % 2 == 0] += int(i % 2 != x % 2)
	print(en[True] if en[True] == en[False] else -1)


x = int(input())
for i in range(x):
	listlen = int(input())
	nums = list(map(int, input().split()))
	badlist = []
	badlistpos = []
	p = 0
	while p < len(nums):
		if nums[p] % 2 != p % 2:
			badlist.append(nums[p])
			badlistpos.append(p)
		p += 1
	(even_count, odd_count) = (0, 0)
	for each in badlistpos:
		if each % 2 == 0:
			even_count += 1
		else:
			odd_count += 1
	if len(badlist) == 0:
		print('0')
	elif even_count != odd_count:
		print('-1')
	else:
		print(int(len(badlist) / 2))


t = int(input())
for i in range(t):
	a = int(input())
	l = [int(i) for i in input().split()]
	e = 0
	o = 0
	for j in range(a):
		if l[j] % 2 != j % 2:
			if j % 2 == 0:
				e += 1
			else:
				o += 1
	if e == o:
		print(o)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = list()
	c = 0
	d = 0
	for i in range(len(l)):
		m.append(l[i] % 2)
	for i in range(0, len(m), 2):
		if m[i] == 1:
			c += 1
	for i in range(1, len(m), 2):
		if m[i] == 0:
			d += 1
	if c != d:
		print('-1')
	else:
		print(c)


def k_even(s):
	k = 0
	for i in s:
		if i % 2 == 0:
			k += 1
	return k

def k_even_even(s):
	k = 0
	n_e = 0
	for i in range(0, len(s), 2):
		n_e += 1
		if s[i] % 2 == 0:
			k += 1
	return (k, n_e)
for _ in range(int(input())):
	n = int(input())
	s = [int(i) for i in input().split()]
	k_e = k_even(s)
	(k_e_e, n_e) = k_even_even(s)
	if n_e != k_e:
		print(-1)
		continue
	print(n_e - k_e_e)


q = int(input())
for z in range(q):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	amodd = 0
	for i in range(n):
		amodd += arr[i] % 2
	if amodd == n // 2:
		res = 0
		for i in range(0, n, 2):
			if arr[i] % 2:
				res += 1
		print(res)
	else:
		print(-1)


nb = int(input())
for i in range(nb):
	compteur = 0
	pair = []
	imp = []
	n = int(input())
	liste = [int(x) for x in input().split()]
	for loop in range(len(liste)):
		if liste[loop] % 2 == 1:
			imp.append(liste[loop])
		else:
			pair.append(liste[loop])
	if len(liste) % 2 == 0:
		if len(pair) != len(imp):
			print(-1)
		else:
			for loop in range(len(liste)):
				roger = loop % 2
				arr = liste[loop] % 2
				if roger != arr:
					compteur += 1
			print(compteur // 2)
	if len(liste) % 2 == 1:
		if len(pair) != len(imp) + 1:
			print(-1)
		else:
			for loop in range(len(liste)):
				roger = loop % 2
				arr = liste[loop] % 2
				if roger != arr:
					compteur += 1
			print(compteur // 2)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(z, x) = (n // 2, n - n // 2)
	(c, v) = (0, 0)
	(b, k) = (0, 0)
	for j in a:
		if j % 2 == 0:
			v += 1
		else:
			c += 1
		if j % 2 != k % 2:
			b += 1
		k += 1
	if z != c or x != v:
		print('-1')
	else:
		print(b // 2)


cnt = int(input())
for _ in range(cnt):
	sayi1 = 0
	sayi2 = 0
	leng = int(input())
	arr = list(map(int, input().split()))
	for i in range(leng):
		if i % 2 == 0 and arr[i] % 2 == 1:
			sayi1 += 1
		elif i % 2 == 1 and arr[i] % 2 == 0:
			sayi2 += 1
	if sayi1 == sayi2:
		print(str(sayi1))
	else:
		print('-1')


from collections import *
import sys

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
t = ri()
for _ in range(t):
	n = ri()
	a = rl()
	even = 0
	odd = 0
	even_target = 0
	odd_target = 0
	for i in range(n):
		if a[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if i % 2 == 0:
			even_target += 1
		else:
			odd_target += 1
	if not (even == even_target and odd == odd_target):
		print(-1)
	else:
		even_to_move = 0
		for i in range(n):
			if i % 2 == 1 and a[i] % 2 == 0:
				even_to_move += 1
		print(even_to_move)


t = int(input())
for i in range(t):
	n = int(input())
	e = 0
	o = 0
	l = [int(i) for i in input().split()]
	for j in range(n):
		if j % 2 == 0 and l[j] % 2 == 1:
			e += 1
		elif j % 2 == 1 and l[j] % 2 == 0:
			o += 1
	if o == e:
		print(e)
	else:
		print(-1)


a = int(input())
for i in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	d = 0
	e = 0
	for i in range(b):
		if i % 2 != c[i] % 2:
			if i % 2 == 0:
				e += 1
			else:
				d += 1
	if e == d:
		print(e)
	else:
		print(-1)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	length = len(a)
	odd = 0
	even = 0
	move = 0
	flag = 0
	for i in range(length):
		if a[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	if length % 2 == 0 and odd != even or (length % 2 == 1 and odd + 1 != even):
		print(-1)
		continue
	for i in range(length):
		if i % 2 != a[i] % 2:
			move += 1
	if move % 2 == 1:
		print(-1)
		continue
	print(move // 2)


t = int(input())
while t > 0:
	n = int(input())
	l = [int(i) for i in input().split()]
	evenind = 0
	oddind = 0
	for i in range(len(l)):
		if i % 2 == 0 and l[i] % 2 != 0:
			evenind += 1
		elif i % 2 != 0 and l[i] % 2 == 0:
			oddind += 1
	if evenind != oddind:
		print(-1)
		t -= 1
		continue
	else:
		print(evenind)
	t -= 1


tcases = int(input())
while tcases:
	tcases -= 1
	n = int(input())
	arr = [int(i) for i in input().split()]
	odd = even = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	s = [int(x) for x in input().split()]
	evens = 0
	ods = 0
	for i in range(n):
		if i % 2 == 0 and s[i] % 2 != 0:
			ods += 1
		if i % 2 != 0 and s[i] % 2 == 0:
			evens += 1
	if ods == evens:
		print(ods)
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	wrongAtEvenIndex = 0
	wrongAtOddIndex = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			wrongAtEvenIndex += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			wrongAtOddIndex += 1
	if wrongAtOddIndex == 0 and wrongAtEvenIndex == 0:
		print(0)
	elif wrongAtEvenIndex != wrongAtOddIndex:
		print(-1)
	else:
		print(wrongAtOddIndex)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cht = 0
	ncht = 0
	for (i, j) in enumerate(a):
		if i % 2 == 0:
			if j % 2 != 0:
				cht += 1
		elif j % 2 == 0:
			ncht += 1
	if cht == ncht:
		print(ncht)
	else:
		print(-1)


def smotr_mas(spisok):
	(chet, nechet) = (0, 0)
	for i in range(len(spisok)):
		if spisok[i] % 2 == 0 and i % 2 == 1:
			chet += 1
		elif spisok[i] % 2 == 1 and i % 2 == 0:
			nechet += 1
	if chet == nechet:
		return chet
	else:
		return -1
pyst_spic = []
for _ in range(int(input())):
	kol_ch = int(input())
	spis = list(map(int, input().split()))
	print(smotr_mas(spis))


def even(arr):
	even = []
	odd = []
	for i in range(len(arr)):
		if i % 2 == 0:
			if arr[i] % 2 != 0:
				odd.append(arr[i])
		elif i % 2 != 0:
			if arr[i] % 2 == 0:
				even.append(arr[i])
	n = len(even)
	m = len(odd)
	i = 0
	c = 0
	while i < len(arr):
		if i % 2 == 0:
			if arr[i] % 2 != 0:
				if n > 0:
					c += 1
					n -= 1
				else:
					return -1
		elif arr[i] % 2 == 0:
			if m > 0:
				c += 1
				m -= 1
			else:
				return -1
		i += 1
	return c // 2
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(even(arr))


testcase = int(input())
while testcase > 0:
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		if l[0] % 2 == 0:
			print(0)
		else:
			print(-1)
	else:
		if n % 2 == 1:
			a = n // 2 + 1
			b = n // 2
		else:
			a = n // 2
			b = n // 2
		m = 0
		x = 0
		y = 0
		for i in range(0, len(l)):
			check = l[i] % 2
			if check == 0:
				x += 1
			else:
				y += 1
			if i % 2 != check:
				m += 1
		if a == x and b == y:
			print(m // 2)
		else:
			print(-1)
	testcase -= 1


import sys
input = sys.stdin.buffer.readline

def solution():
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		cnt1 = 0
		cnt2 = 0
		for i in range(n):
			if i % 2 == 0 and l[i] % 2 == 1:
				cnt1 += 1
			elif l[i] % 2 == 0 and i % 2 == 1:
				cnt2 += 1
		if cnt1 != cnt2:
			print(-1)
		else:
			print(cnt1)
solution()


t = int(input())
for _ in range(t):
	n = int(input())
	lsum = [0, 0]
	lst = list(map(int, input().split()))
	for i in range(n):
		if lst[i] % 2 != i % 2:
			lsum[i % 2] += 1
	if lsum[0] == lsum[1]:
		print(lsum[0])
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 == 0:
				b.append(0)
			else:
				b.append('e')
		elif a[i] % 2 != 0:
			b.append(0)
		else:
			b.append('o')
	c1 = b.count('e')
	c2 = b.count('o')
	if c1 != c2:
		print(-1)
	else:
		print(c1)


import math
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 != 0:
		o = n // 2
		e = n - o
	else:
		o = n // 2
		e = n - o
	o1 = 0
	e1 = 0
	c1 = 0
	c2 = 0
	for j in range(len(a)):
		if a[j] % 2 == 0:
			e1 = e1 + 1
		if a[j] % 2 != 0:
			o1 = o1 + 1
		if a[j] % 2 == 0 and j % 2 == 0:
			c1 = c1 + 1
		if a[j] % 2 != 0 and j % 2 != 0:
			c2 = c2 + 1
	e1 = e1 - c1
	o1 = o1 - c2
	if e1 == o1:
		print(e1)
	else:
		print(-1)


def Even_array(a):
	e = 0
	o = 0
	for i in range(len(a)):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				e += 1
			else:
				o += 1
	if e != o:
		return -1
	else:
		return e
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(Even_array(a))


t = int(input())
while t > 0:
	t -= 1
	ct = 0
	odd = 0
	even = 0
	n = int(input())
	a = list(map(int, input().split()))
	for i in a:
		if i % 2 == 1:
			odd += 1
		else:
			even += 1
	if n % 2 == 1 and even - odd != 1:
		print(-1)
		continue
	if n % 2 == 0 and even != odd:
		print(-1)
		continue
	i = 0
	while i < n:
		if i % 2 == 1 and a[i] % 2 != 1:
			ct += 1
		if i % 2 == 0 and a[i] % 2 != 0:
			ct += 1
		i += 1
	print(ct // 2)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		o = 0
		e = 0
		for (i, v) in enumerate(a):
			if v % 2 != i % 2:
				o += v % 2 == 1
				e += v % 2 == 0
		if o != e:
			print(-1)
		else:
			print(o)
	return
main()


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	n = I()
	a = li()
	c = 0
	d = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2:
				c += 1
			else:
				d += 1
	if c != d:
		print(-1)
	else:
		print(c)
for _ in range(I()):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	List = list(map(int, input().split()))
	count_odd = 0
	divert = 0
	for x in range(n):
		if List[x] % 2 != 0:
			count_odd += 1
			if x % 2 == 0:
				divert += 1
	if n // 2 == count_odd:
		print(divert)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	count2 = 0
	for i in range(n):
		if a[i] % 2 == 0 and i % 2 == 1:
			count += 1
		elif a[i] % 2 == 1 and i % 2 == 0:
			count2 += 1
	if count == count2:
		print(count)
	else:
		print('-1')


for test in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ind = [0, 0]
	ele = [0, 0]
	for i in range(n):
		if arr[i] % 2 != i % 2:
			ind[i % 2] += 1
			ele[arr[i] % 2] += 1
	if ind == ele:
		print(sum(ind) // 2)
	else:
		print(-1)


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	odd = even = 0
	for i in range(len(a)):
		if i & 1 != a[i] & 1:
			if i & 1:
				even += 1
			else:
				odd += 1
	print(odd if odd == even else -1)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	e = 0
	o = 0
	swap = 0
	count = 0
	for i in range(0, n):
		if i % 2 == 0:
			if l[i] % 2 == 0:
				continue
			else:
				o += 1
		if i % 2 == 1:
			if l[i] % 2 == 1:
				continue
			else:
				e += 1
	if o == e:
		print(o)
	else:
		print(-1)
	t = t - 1


def helper(n, lst):
	(even, odd) = (0, 0)
	for i in range(n):
		if i % 2 != lst[i] % 2:
			if lst[i] % 2:
				even += 1
			else:
				odd += 1
	return -1 if odd != even else odd
for _ in range(int(input())):
	m = int(input())
	a = [int(j) for j in input().split()]
	print(helper(m, a))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if a[i] % 2 != i % 2:
			if (a[i] % 2, i % 2) not in d:
				d[a[i] % 2, i % 2] = 1
			else:
				d[a[i] % 2, i % 2] += 1
	(k, k1) = (0, 0)
	if (1, 0) in d:
		k = d[1, 0]
	if (0, 1) in d:
		k1 = d[0, 1]
	if k == k1:
		print(k)
	else:
		print(-1)


ans = []
for _ in range(int(input())):
	n = int(input())
	arr = list(map(lambda x: int(x) % 2, input().split()))
	w = 0
	if n % 2 == 0:
		if arr.count(0) == n // 2:
			for i in range(n):
				if i % 2 != arr[i]:
					w += 1
			print(w // 2)
		else:
			print(-1)
	elif arr.count(0) == (n + 1) // 2:
		for i in range(n):
			if i % 2 != arr[i]:
				w += 1
		print(w // 2)
	else:
		print(-1)


t = int(input())
for j in range(t):
	s = int(input())
	l = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(s):
		if l[i] % 2 == 1 and i % 2 == 0:
			odd += 1
		elif l[i] % 2 == 0 and i % 2 == 1:
			even += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


def imp(s):
	l = len(s)
	(e, o) = (0, 0)
	for q in s:
		if q % 2 == 0:
			e += 1
		else:
			o += 1
	if l % 2 == 0:
		if e == o:
			return True
		else:
			return False
	elif (l - 1) // 2 == o and (l + 1) // 2 == e:
		return True
	else:
		return False

def res(s):
	if imp(s):
		point = 0
		cont = 0
		while point <= len(s) - 1:
			if point % 2 == 0 and s[point] % 2 != 0:
				cont += 1
			point += 1
		return cont
	else:
		return -1
t = int(input())
for i in range(t):
	l = int(input())
	s = [int(x) for x in list(input().split())]
	print(res(s))


tc = int(input())
for _ in range(tc):
	n = int(input())
	arr = list(map(int, input().split()))
	(even_galat, odd_galat) = (0, 0)
	for i in range(0, len(arr)):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				even_galat += 1
			else:
				odd_galat += 1
	if even_galat == odd_galat:
		print(even_galat)
	else:
		print(-1)


import math
t = int(input())
for tc in range(t):
	n = int(input())
	line = input().split()
	arr = []
	counteven = 0
	for i in range(n):
		arr.append(int(line[i]))
		if arr[-1] % 2 == 0:
			counteven += 1
	if n % 2 != 0:
		if counteven != math.ceil(n / 2):
			print('-1')
			continue
	if n % 2 == 0:
		if counteven != n // 2:
			print('-1')
			continue
	if n == 1:
		if arr[0] % 2 == 0:
			print('0')
		else:
			print('-1')
		continue
	ans = 0
	for i in range(0, n, 2):
		if arr[i] % 2 != 0:
			ans += 1
	print(ans)


n = int(input())
for i in range(n):
	a = int(input())
	b = [int(j) for j in input().split(' ')]
	count1 = 0
	count = {1: 0, 0: 0}
	for (idx, j) in enumerate(b):
		if (idx - j) % 2 == 0:
			count1 += 1
		else:
			count[int(j % 2)] += 1
	if count[1] == count[0]:
		print(count[1])
	else:
		print(-1)


for iota in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	check = 0
	ans = 0
	for i in range(n):
		if i % 2 == lst[i] % 2:
			continue
		elif lst[i] % 2 == 0:
			check += 1
			ans += 1
			continue
		else:
			check -= 1
	if check == 0:
		print(ans)
	else:
		print(-1)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ev = 0
	od = 0
	for i in range(n):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				ev += 1
		elif l[i] % 2 == 0:
			od += 1
	if od == ev:
		print(od)
	else:
		print(-1)


import sys
import math
from collections import defaultdict

def solve(test):
	n = int(input())
	a = list(map(int, input().split()))
	(odd, even) = (0, 0)
	for i in range(n):
		if i & 1:
			if not a[i] & 1:
				even += 1
		elif a[i] & 1:
			odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	oc = 0
	ec = 0
	out_of_place = 0
	for i in range(n):
		x = ar[i]
		if ar[i] % 2 != i % 2:
			out_of_place += 1
		if x % 2 == 1:
			oc += 1
		else:
			ec += 1
	reqeven = (n + 1) // 2
	reqodd = n // 2
	if reqodd != oc:
		print(-1)
	else:
		print(out_of_place // 2)


for i in range(int(input())):
	c = int(input())
	c = 0
	x = 0
	y = 0
	l = list(map(int, input().split()))
	for i in range(0, len(l)):
		if l[i] % 2 == 0 and i % 2 != 0 or (l[i] % 2 != 0 and i % 2 == 0):
			if l[i] % 2 == 0:
				x += 1
			else:
				y += 1
			c += 1
	print(int(c / 2) if c % 2 == 0 and x == y else -1)


import sys

class BEvenArray:

	def solve(self, tc=0):
		for _ in range(int(input())):
			n = int(input())
			a = [int(_) for _ in input().split()]
			bad = [[], []]
			for i in range(n):
				if i % 2 != a[i] % 2:
					bad[i % 2].append(i)
			print(len(bad[0]) if len(bad[0]) == len(bad[1]) else -1)
solver = BEvenArray()
input = sys.stdin.readline
solver.solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	p = [0] * 2
	for i in a:
		p[i & 1] += 1
	if p[0] < p[1] or p[0] - p[1] > 1:
		print(-1)
		continue
	cnt = 0
	for i in range(n):
		if not i & 1 == a[i] & 1:
			cnt += 1
	print((cnt + 1) // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	st = [int(k) for k in input().split()]
	mod = []
	lim = []
	dic = {}
	for i in range(len(st)):
		mod.append(i % 2)
		lim.append(st[i] % 2)
	count = 0
	for i in range(len(st)):
		if mod[i] != lim[i]:
			if (mod[i], lim[i]) not in dic:
				dic[mod[i], lim[i]] = 1
			else:
				dic[mod[i], lim[i]] += 1
	if (1, 0) in dic and (0, 1) not in dic:
		print(-1)
	elif (0, 1) in dic and (1, 0) not in dic:
		print(-1)
	elif (1, 0) in dic and (0, 1) in dic:
		if dic[1, 0] == dic[0, 1]:
			print(dic[0, 1])
		else:
			print(-1)
	else:
		print(0)


a = int(input())
ans = ''
for i in range(a):
	n = int(input())
	A = list(map(int, input().split()))
	one = 0
	zero = 0
	for i in range(len(A)):
		if A[i] % 2 != i % 2:
			if A[i] % 2 == 1:
				one += 1
			else:
				zero += 1
	if one != zero:
		ans += '-1\n'
	else:
		ans += str(min(one, zero)) + '\n'
print(ans)


def even(values):
	count_odd = 0
	count_even = 0
	for i in range(len(values)):
		if i % 2 == 0:
			if values[i] % 2 == 1:
				count_odd = count_odd + 1
		elif i % 2 == 1:
			if values[i] % 2 == 0:
				count_even = count_even + 1
	if count_even == count_odd:
		return count_even
	else:
		return -1
t = int(input())
for i in range(t):
	n = int(input())
	values = list(map(int, input().split()))
	print(even(values))


t = int(input())
for q in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	o = 0
	e = 0
	p = 0
	for i in range(n):
		if a[i] % 2 == 1:
			o = o + 1
		if a[i] % 2 != i % 2:
			p = p + 1
	if o != n // 2:
		print(-1)
		continue
	if p % 2 == 0:
		print(int(p / 2))
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	(d, d1) = (0, 0)
	for i in range(n):
		if i % 2 != b[i] % 2:
			if i % 2 == 0:
				d = d + 1
			else:
				d1 = d1 + 1
	if d != d1:
		print(-1)
	elif d == d1:
		print(d)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	odd = 0
	even = 0
	count = 0
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 == 0 or (i & 1 and l[i] & 1):
			pass
		elif l[i] % 2:
			odd += 1
			count += 1
		else:
			even += 1
			count += 1
	if odd == even:
		print(count // 2)
	else:
		print(-1)


t = int(input())
f = []
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even = [1 if i % 2 == 0 and a[i] % 2 != 0 else -1 if i % 2 != 0 and a[i] % 2 == 0 else 0 for i in range(len(a))]
	if sum(even) == 0:
		print(even.count(1))
	else:
		print(-1)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	l = [int(i) for i in input().split()]
	(p, c) = (0, 0)
	for i in range(0, n):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				c = c + 1
				p = p + 1
		elif l[i] % 2 == 0:
			c = c - 1
	if c == 0:
		print(p)
	else:
		print(-1)


def evencounter(a):
	oc = 0
	ec = 0
	for i in a:
		if i % 2 == 0:
			ec += 1
		else:
			oc += 1
	return ec

def movecounter(a):
	count = 0
	for i in range(len(a)):
		if i % 2 != 0 and a[i] % 2 == 0:
			count += 1
	return count
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n % 2 == 0 and evencounter(l) == n // 2:
		print(movecounter(l))
	elif n % 2 != 0 and evencounter(l) == n // 2 + 1:
		print(movecounter(l))
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	oddcnt = 0
	evecnt = 0
	for i in range(len(l)):
		if l[i] % 2 != i % 2:
			if l[i] % 2 == 0:
				evecnt += 1
			else:
				oddcnt += 1
	if oddcnt == 0 and evecnt == 0:
		print(0)
	elif oddcnt == evecnt:
		print(oddcnt)
	else:
		print(-1)


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))
	o = 0
	e = 0
	for i in range(n):
		x = i % 2
		y = a[i] % 2
		if y != x:
			if y == 1:
				o = o + 1
			else:
				e = e + 1
	if o == e:
		print(o)
	else:
		print('-1')
	t = t - 1


t = int(input())
sols = []
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().strip().split()))
	parity = []
	for i in range(n):
		if nums[i] % 2 != i % 2:
			if nums[i] % 2 == 0:
				parity.append(1)
			else:
				parity.append(2)
		else:
			parity.append(0)
	if parity.count(1) == parity.count(2):
		sols.append(parity.count(1))
	else:
		sols.append(-1)
for o in sols:
	print(o)


for i in range(int(input())):
	n = int(input())
	a = [int(i) % 2 for i in input().split()][:n]
	zero = a.count(0)
	one = a.count(1)
	d = 0
	if n % 2 == 0:
		if one != n // 2 and zero != n // 2:
			print(-1)
		else:
			for j in range(len(a)):
				c = j % 2
				if c != a[j]:
					d += 1
			print(d // 2)
	elif zero != n // 2 + 1:
		print(-1)
	else:
		for j in range(len(a)):
			c = j % 2
			if c != a[j]:
				d += 1
		print(d // 2)


for _ in range(int(input())):
	(e, o, n) = ([], [], int(input()))
	t = list(map(int, input().split(' ')))
	for i in range(n):
		c = t[i] % 2
		if c != i % 2:
			if c:
				o.append(i)
			else:
				e.append(i)
	if len(e) == len(o):
		print(len(e))
	else:
		print(-1)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	bo = be = 0
	for i in range(n):
		if i % 2 == 1 and a[i] % 2 == 0:
			bo += 1
		elif i % 2 == 0 and a[i] % 2 == 1:
			be += 1
	if bo == be:
		print(be)
	else:
		print(-1)
t = 1
t = int(input())
for _ in range(t):
	solve()


for tc in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	miss = 0
	o = 0
	oi = 0
	e = 0
	ei = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			miss += 1
		if l[i] % 2 == 0:
			e += 1
		elif l[i] % 2 == 1:
			o += 1
		if i % 2 == 0:
			ei += 1
		elif i % 2 == 1:
			oi += 1
	if not (oi == o and ei == e):
		print(-1)
	elif miss % 2 == 0:
		print(miss // 2)
	else:
		print(-1)


d = int(input())
for _ in range(d):
	t = int(input())
	a = list(map(int, input().split()))
	c = 0
	c1 = 0
	for i in range(0, len(a)):
		if a[i] % 2 == 1 and i % 2 == 0:
			c += 1
		elif a[i] % 2 == 0 and i % 2 == 1:
			c1 += 1
	if c == c1:
		print(c)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	size = int(input())
	l = list(map(int, input().split()))
	eve = 0
	odd = 0
	for i in range(size):
		if i % 2 != l[i] % 2:
			if i % 2 == 0:
				eve = eve + 1
			else:
				odd = odd + 1
	if eve == odd:
		print(eve)
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	s = input().split()
	l = []
	i = 0
	while i < n:
		l.append(int(s[i]))
		i += 1
	i = 0
	oddwrng = 0
	evenwrng = 0
	while i < n:
		if i % 2 == 0 and l[i] % 2 != 0:
			evenwrng += 1
		if i % 2 != 0 and l[i] % 2 == 0:
			oddwrng += 1
		i += 1
	if oddwrng == evenwrng:
		print(oddwrng)
	else:
		print('-1')
	t -= 1


T = int(input())
for i in range(0, T):
	n = int(input())
	A = list(map(int, input().split()))
	odd_ind_even = 0
	even_ind_odd = 0
	for j in range(0, n):
		if j % 2 == 0:
			if A[j] % 2 != 0:
				even_ind_odd += 1
		elif A[j] % 2 == 0:
			odd_ind_even += 1
	if odd_ind_even != even_ind_odd:
		print(-1)
	else:
		print(odd_ind_even)


for ii in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	noo = 0
	noe = 0
	for i in a:
		if i % 2 == 0:
			noe += 1
		else:
			noo += 1
	if noe != (n + 1) // 2:
		print(-1)
	else:
		nce = 0
		nco = 0
		for i in range(n):
			if a[i] % 2 == 0 and i % 2 != 0:
				nce += 1
			if a[i] % 2 == 1 and i % 2 == 0:
				nco += 1
		if nce != nco:
			print(-1)
		else:
			print(nce)


for _ in range(int(input())):
	n = int(input())
	odd = 0
	even = 0
	step = 0
	arr = list(map(int, input().split()))
	for i in range(0, n):
		if i % 2 != 0:
			if arr[i] % 2 != 0:
				continue
			elif even != 0:
				step += 1
				even -= 1
			else:
				odd += 1
		elif arr[i] % 2 == 0:
			continue
		elif odd != 0:
			step += 1
			odd -= 1
		else:
			even += 1
	if even != 0 or odd != 0:
		step = -1
	print(step)


def ints():
	return list(map(int, input().split()))
for _ in range(int(input())):
	n = int(input())
	a = ints()
	zc = 0
	oc = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			oc += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			zc += 1
	if oc == zc:
		print(oc)
	else:
		print(-1)


t = int(input())
inList = []
for temp in range(t):
	crap = input()
	inList.append(list(map(int, input().split())))

def solve(inList):
	count = 0
	moves = 0
	rList = inList
	for i in rList:
		if i % 2 != count % 2:
			for j in range(len(rList)):
				if j != count and rList[j] % 2 != rList[count] % 2:
					if j % 2 != rList[j] % 2 and rList[j] % 2 == count % 2:
						temp = rList[j]
						rList[j] = rList[count]
						rList[count] = temp
						moves += 1
		count += 1
	count2 = 0
	for k in rList:
		if k % 2 != count2 % 2:
			return -1
		count2 += 1
	return moves
for i in inList:
	print(solve(i))


t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	a = 0
	b = 0
	for i in range(n):
		if i % 2 == 0:
			if x[i] % 2 == 1:
				a = a + 1
		elif x[i] % 2 == 0:
			b = b + 1
	if a == b:
		print(a)
	else:
		print(-1)


t = int(input())
for ex in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	even_num = int(0)
	odd_num = int(0)
	w_even_num = int(0)
	w_odd_num = int(0)
	for i in range(n):
		if a[i] % 2 == 0:
			even_num += 1
			if i % 2 != 0:
				w_even_num += 1
		else:
			odd_num += 1
			if i % 2 != 1:
				w_odd_num += 1
	if w_even_num != w_odd_num:
		print('-1')
	else:
		print(w_odd_num)


from sys import stdin
t = int(input())
for i in range(t):
	a = int(input())
	arr = [int(num) for num in stdin.readline().split()]
	par_1 = 0
	par_0 = 0
	for (index, num) in enumerate(arr):
		if index % 2 != num % 2:
			if num % 2:
				par_0 += 1
			else:
				par_1 += 1
	if par_1 == par_0:
		print(par_1)
	else:
		print(-1)


import math
t = int(input())
while t != 0:
	n = int(input())
	nums = list(map(int, input().split()))
	i = 0
	count = 0
	wrong_elems_num = []
	wrong_elems_index = []
	while i < len(nums):
		if nums[i] % 2 != i % 2:
			wrong_elems_index.append(i % 2)
			wrong_elems_num.append(nums[i] % 2)
			count += 1
		i += 1
	if sorted(wrong_elems_num) == sorted(wrong_elems_index):
		if count % 2 == 0:
			print(int(count / 2))
		else:
			print(int(count / 2) + 1)
	else:
		print(-1)
	t -= 1


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	d = {0: 0, 1: 0}
	for i in range(n):
		if i % 2 != a[i] % 2:
			d[i % 2] += 1
	if d[0] != d[1]:
		print(-1)
	else:
		print(d[0])
t = int(input())
for _ in range(t):
	solve()


test = int(input())
while test != 0:
	asize = int(input())
	a = input()
	a = a.split()
	b = 0
	c = 0
	for x in range(0, len(a)):
		if x % 2 == 0:
			if int(a[x]) % 2 != 0:
				b += 1
		elif int(a[x]) % 2 == 0:
			c += 1
	if b == c:
		print((b + c) // 2)
	else:
		print(-1)
	test -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	dict = {1: 0, 0: 0}
	for i in range(n):
		i1 = i % 2
		if i1 == arr[i] % 2:
			pass
		else:
			dict[i1] += 1
	if dict.get(1) == dict.get(0):
		print(dict[1])
	else:
		print(-1)


import math
for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	notmatch = [0, 0]
	for i in range(n):
		if i % 2 != array[i] % 2:
			notmatch[i % 2] += 1
	if notmatch[0] == notmatch[1]:
		print(notmatch[0])
	else:
		print(-1)


T = int(input())
for _ in range(T):
	input()
	arr = list(map(int, input().split()))
	errors_index = []
	for i in range(len(arr)):
		if i % 2 != arr[i] % 2:
			errors_index.append(i)
	cnt = 0
	solved = []
	cleared = True
	while len(errors_index) > len(solved):
		possible = False
		for i in range(len(errors_index)):
			for j in range(len(errors_index)):
				if i == j:
					continue
				if i in solved or j in solved:
					continue
				a = errors_index[i]
				b = errors_index[j]
				if arr[a] % 2 == b % 2 and arr[b] % 2 == a % 2:
					cnt += 1
					possible = True
					temp = arr[a]
					arr[a] = arr[b]
					arr[b] = temp
					solved.append(i)
					solved.append(j)
		if not possible:
			cleared = False
			print('-1')
			break
	if cleared:
		print(cnt)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
for i in range(ip()):
	n = ip()
	li = ai()
	even = odd = 0
	for i in range(n):
		if i % 2 != li[i] % 2:
			if li[i] % 2:
				odd += 1
			else:
				even += 1
	if odd != even:
		print(-1)
	else:
		print(odd)


from sys import stdin
_input = stdin.readline
(_int, _range) = (int, range)

def solution():
	for _ in _range(_int(_input())):
		n = _int(_input())
		arr = [_int(i) for i in _input().split()]
		counter = [0, 0]
		for i in _range(n):
			if i % 2 != arr[i] % 2:
				counter[i % 2] += 1
		if counter[0] != counter[1]:
			print(-1)
		else:
			print(counter[0])
solution()


t = int(input())
for i in range(t):
	n = int(input())
	lst1 = list(map(int, input().split()))
	ev = 0
	od = 0
	lst2 = []
	for i in range(len(lst1)):
		if lst1[i] % 2 == 0:
			ev += 1
			if i % 2 != 0:
				lst2.append(lst1[i])
		else:
			od += 1
	if len(lst1) % 2 == 0:
		if ev == od:
			print(len(lst2))
		else:
			print(-1)
	elif ev == od + 1:
		print(len(lst2))
	else:
		print(-1)


def nod(a, b):
	while a != b:
		(a, b) = (max(a, b), min(a, b))
		if a % b == 0:
			a -= (a // b - 1) * b
		else:
			a -= a // b * b
	return a
for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	(t1, t0) = [0] * 2
	for i in range(n):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				t0 += 1
			else:
				t1 += 1
	if t1 != t0:
		print(-1)
	else:
		print(max(t0, t1))


from math import ceil
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	x = ceil(n / 2)
	if len(list(filter(lambda x: x % 2 == 0, arr))) != x:
		print(-1)
	else:
		print(len(list(filter(lambda x: x % 2 != arr[x] % 2, range(n)))) // 2)


def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	(wrong_even, wrong_odd) = [0, 0]
	for i in range(n):
		if i % 2 == 1 and arr[i] % 2 == 0:
			wrong_odd += 1
		elif i % 2 == 0 and arr[i] % 2 == 1:
			wrong_even += 1
	if wrong_even == wrong_odd:
		return wrong_odd
	return -1
t = int(input())
while t:
	print(solve())
	t -= 1


import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
for _ in range(inp()):
	n = inp()
	x = ip()
	(e, o) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			if x[i] % 2:
				e += 1
		elif x[i] % 2 == 0:
			o += 1
	if o == e:
		print(o)
	else:
		print(-1)


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i = j = 0
	for x in range(len(a)):
		if a[x] % 2 != x % 2:
			if x % 2 == 0:
				i += 1
			else:
				j += 1
	if i == j:
		print(i)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list((int(num) for num in input().split()))
	e = []
	o = []
	for z in range(0, len(a)):
		if z % 2 != a[z] % 2:
			if a[z] % 2 == 0:
				e.append(a[z])
			else:
				o.append(a[z])
	if len(e) != len(o):
		print('-1')
	else:
		print(len(e))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	z = 0
	o = 0
	for j in range(n):
		if j % 2 == 0 and l[j] % 2 != 0:
			z += 1
		elif j % 2 == 1 and l[j] % 2 != 1:
			o += 1
	if z == o:
		print(z)
	else:
		print(-1)


a = int(input())
for j in range(a):
	c = int(input())
	b = input().split()
	n = 0
	ch = 0
	for i in range(c):
		if int(b[i]) % 2 == 0 and i % 2 != 0:
			ch += 1
		elif int(b[i]) % 2 != 0 and i % 2 == 0:
			n += 1
	if n == ch:
		print(n)
	else:
		print(-1)


import sys

def ii():
	return sys.stdin.readline().strip()

def idata():
	return [int(x) for x in ii().split()]

def solve_of_problem():
	(a, b) = (0, 0)
	n = int(ii())
	data = idata()
	for i in range(n):
		if i % 2 == 1 and data[i] % 2 == 0:
			a += 1
		elif i % 2 == 0 and data[i] % 2 == 1:
			b += 1
	if a == b:
		print(a)
	else:
		print(-1)
	return
for t in range(int(ii())):
	solve_of_problem()


try:
	T = int(input())
	for _ in range(T):
		N = int(input())
		A = list(map(int, input().split()))
		Parity = []
		Wrong = []
		even = 0
		odd = 0
		for i in range(N):
			if i % 2 == A[i] % 2:
				Parity.append('Y')
			else:
				Parity.append('N')
				Wrong.append(A[i])
		for j in Wrong:
			if j % 2 == 0:
				even += 1
			else:
				odd += 1
		if Parity.count('Y') == N:
			print(0)
		elif len(Wrong) % 2 != 0:
			print(-1)
		elif len(Wrong) % 2 == 0:
			if odd == even:
				print(even)
			else:
				print(-1)
except EOFError:
	pass


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	a = []
	b = []
	oddi = 0
	eveni = 0
	oddl = 0
	evenl = 0
	for i in range(len(l)):
		if i % 2 == l[i] % 2:
			continue
		else:
			a.append(i)
			b.append(l[i])
	for i in range(len(a)):
		if a[i] % 2 == 0:
			eveni += 1
		else:
			oddi += 1
	for i in range(len(b)):
		if b[i] % 2 == 0:
			evenl += 1
		else:
			oddl += 1
	if eveni == oddi and evenl == oddl:
		print(eveni)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	x = [int(x) for x in input().split()]
	if len(x) == 0:
		print(0)
		continue
	ev = []
	od = []
	bad = []
	for i in range(len(x)):
		if x[i] % 2 != 0 and i % 2 == 0:
			bad.append(i)
			ev.append(i)
		if x[i] % 2 == 0 and i % 2 != 0:
			bad.append(i)
			od.append(i)
	if len(bad) == 0:
		print(0)
		continue
	if len(ev) == len(od):
		print(len(ev))
		continue
	print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	k = 0
	odd = []
	even = []
	for i in range(n):
		if i % 2 == a[i] % 2:
			k += 1
		elif i % 2:
			odd.append(i)
		else:
			even.append(i)
	if n == k:
		print(0)
	elif len(odd) == len(even):
		print(len(odd))
	else:
		print(-1)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	a = LI()
	count = 0
	x = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2 == 1:
				count += 1
			else:
				x += 1
	if count != x:
		print(-1)
	else:
		print(count)


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	odd = 0
	eve = 0
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 != 0:
			odd += 1
		elif i % 2 != 0 and l[i] % 2 == 0:
			eve += 1
	if eve != odd:
		print(-1)
	else:
		print(eve)


for i in range(int(input())):
	t = int(input())
	l = [int(x) for x in input().split()]
	ans = 0
	original = []
	duplicate = []
	for i in range(t):
		if i % 2 == 0:
			original.append(0)
		else:
			original.append(1)
	for i in range(t):
		duplicate.append(l[i] % 2)
	o = original.count(0)
	d = duplicate.count(0)
	if o == d:
		i = 0
		while i < t:
			if l[i] % 2 != 0:
				ans += 1
			else:
				ans = ans
			i = i + 2
	else:
		ans = -1
	print(ans)


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = int(input())
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	n = inp()
	a = inlt()
	mismatched = 0
	even = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 0 or (i % 2 == 1 and a[i] % 2 == 1):
			pass
		else:
			mismatched += 1
		if a[i] % 2 == 0:
			even += 1
	odd = n - even
	if n % 2 == 0 and 2 * even != n or (n % 2 == 1 and 2 * even != n + 1):
		print(-1)
	elif mismatched % 2 == 1:
		print(-1)
	else:
		print(mismatched // 2)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	eve = 0
	for i in a:
		if i % 2 == 0:
			eve += 1
	odd = n - eve
	if n % 2 == 0 and eve != odd:
		print('-1')
	elif n % 2 == 1 and eve != odd + 1:
		print('-1')
	else:
		c = 0
		for i in range(0, len(a), 2):
			if a[i] % 2 != 0:
				c += 1
		print(c)
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(o, e, total) = (0, 0, 0)
	for i in range(n):
		ind = i % 2
		val = arr[i] % 2
		if ind != val:
			total += 1
		if val == 0:
			e += 1
		else:
			o += 1
	if n % 2 == 0:
		if o != e:
			print(-1)
		else:
			print(total // 2)
	elif e == o + 1:
		print(total // 2)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(a, b, cnt) = (0, 0, 0)
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n):
		if arr[i] % 2 == 1:
			a += 1
		else:
			b += 1
		if i % 2 != arr[i] % 2:
			cnt += 1
	if cnt == 1 or cnt % 2 == 1:
		print(-1)
	elif n % 2 == 0:
		if a == b:
			print(cnt // 2)
		else:
			print(-1)
	elif abs(a - b) == 1:
		print(cnt // 2)
	else:
		print(-1)


def moves_to_make_even(arr):
	a = 0
	b = 0
	for (idx, val) in enumerate(arr):
		if idx % 2 != val % 2:
			if val % 2 == 0:
				a += 1
			else:
				b += 1
	return -1 if a != b else a
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(moves_to_make_even(arr))


e = []
o = []
t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	for i in range(n):
		if i % 2 == 0:
			if int(a[i]) % 2 != 0:
				o.append(a[i])
		elif i % 2 != 0:
			if int(a[i]) % 2 == 0:
				e.append(a[i])
	if len(e) != len(o):
		print(-1)
	else:
		print(len(e))
	e = []
	o = []


ll = lambda : list(map(int, input().split()))
s = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
from collections import *
for _ in range(ii()):
	a = ii()
	l = ll()
	s = [0] * a
	f = 1
	c = 0
	e = 0
	for i in range(a):
		if f == 1:
			if l[i] % 2 != 0:
				c += 1
			f = 0
		else:
			if l[i] % 2 == 0:
				e += 1
			f = 1
	if c == e:
		print(c)
	else:
		print(-1)


for t in range(int(input())):
	(n, i, c) = (int(input()), 0, [0, 0])
	arr = [int(x) for x in input().split()]
	while i < n:
		if i & 1 != arr[i] & 1:
			c[i & 1] += 1
		i += 1
	if c[0] == c[1]:
		print(c[0])
	else:
		print(-1)


from sys import stdin, stdout
from collections import defaultdict as dd
from collections import Counter as ctr
import statistics
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	e = o = 0
	for i in range(n):
		if i & 1:
			if not a[i] & 1:
				e += 1
		elif a[i] & 1:
			o += 1
	if e == o:
		print(e)
	else:
		print(-1)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	for _ in range(int(input())):
		n = int(input())
		arr = read()
		lis = [0, 0]
		for i in range(n):
			if i % 2 != arr[i] % 2:
				lis[i % 2] += 1
		if lis[0] != lis[1]:
			print(-1)
		else:
			print(lis[0])
solve()


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().rstrip().split(' ')))
	c = 0
	v = 0
	if n >= 2:
		for i in range(n):
			if i % 2 == l[i] % 2:
				continue
			elif i % 2 == 0:
				c += 1
			else:
				v += 1
		if c == v:
			print(c)
		else:
			print('-1')
	elif l[0] % 2 == 1:
		print('-1')
	else:
		print(0)


t = int(input())
while t:
	n = int(input())
	l = [int(x) for x in input().split()]
	e = 0
	o = 0
	for i in range(n):
		if l[i] & 1 == i & 1:
			continue
		elif l[i] & 1 == 1:
			e += 1
		else:
			o += 1
	if o == e:
		print(o)
	else:
		print('-1')
	t = t - 1


def main(num, lst):
	odds = 0
	for i in lst:
		if i % 2:
			odds += 1
	if odds != num // 2:
		return -1
	else:
		notInPlace = 0
		for i in range(num):
			if lst[i] % 2 != i % 2:
				notInPlace += 1
		return notInPlace // 2
for _ in range(int(input())):
	num = int(input())
	lst = list(map(int, input().split()))
	print(main(num, lst))


Q = int(input())
for q in range(Q):
	N = int(input())
	L = list(map(int, input().split()))
	Eve_Odd = 0
	Odd_Eve = 0
	for i in range(N):
		if i % 2 != L[i] % 2:
			if i % 2 == 0:
				Eve_Odd += 1
			else:
				Odd_Eve += 1
	if Eve_Odd == Odd_Eve:
		print(Eve_Odd)
	else:
		print(-1)


import collections
import itertools
import sys
from collections import defaultdict, Counter
from math import sqrt, ceil
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	n = inp()
	for _ in range(n):
		dd = inp()
		v = inlt()
		(o, e) = (0, 0)
		for (i, vv) in enumerate(v):
			if i % 2 == 0 and vv % 2 != 0:
				o += 1
			elif i % 2 != 0 and vv % 2 == 0:
				e += 1
		if o != e:
			print(-1)
		else:
			print(e)
main()


t = int(input())
for s in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even = []
	odd = []
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				even.append(i)
			else:
				odd.append(i)
	if len(odd) == len(even):
		print(len(odd))
	else:
		print(-1)


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil, pi
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	oddWrong = 0
	evenWrong = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			if arr[i] % 2 == 1:
				evenWrong += 1
		elif arr[i] % 2 == 0:
			oddWrong += 1
	if oddWrong == evenWrong:
		print(oddWrong)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	(x, y) = (0, 0)
	for (i, a) in enumerate(A):
		if i % 2 != a % 2:
			if i % 2 == 0 and a % 2 == 1:
				x += 1
			else:
				y += 1
	if x == y:
		print(x)
	else:
		print(-1)


t = int(input())
for x in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	even = 0
	c = 0
	if n == 1:
		if arr[0] % 2 == 0:
			print('0')
		else:
			print('-1')
	else:
		for i in arr:
			if i % 2 == 0:
				even += 1
		for i in range(0, n, 2):
			if arr[i] % 2 == 0:
				c += 1
		p = n // 2
		if n % 2 == 1:
			p = n // 2 + 1
		if even != p:
			print('-1')
		else:
			print(even - c)


t = int(input())
for e in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in range(n):
		if i % 2 != 0 and a[i] % 2 != 0:
			b.append(0)
		elif i % 2 == 0 and a[i] % 2 == 0:
			b.append(0)
		elif i % 2 == 0 and a[i] % 2 != 0:
			b.append(1)
		elif i % 2 != 0 and a[i] % 2 == 0:
			b.append(2)
	k = b.count(1)
	l = b.count(2)
	if k == l:
		rs = k
	else:
		rs = -1
	print(rs)


list = []
for i in range(0, int(input())):
	input()
	list.append(input().split())
for a in list:
	(n, ch) = (0, 0)
	for i in range(0, len(a)):
		if i % 2 == int(a[i]) % 2:
			pass
		elif i % 2 == 0 and int(a[i]) % 2 == 1:
			n += 1
		elif i % 2 == 1 and int(a[i]) % 2 == 0:
			ch += 1
	if n == ch:
		print(n)
	elif n != ch:
		print('-1')


for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	odd = sum([1 if a[i] % 2 == 1 else 0 for i in range(n)])
	if odd != n // 2:
		print(-1)
	else:
		min_move = sum([1 if i % 2 != a[i] % 2 else 0 for i in range(n)]) // 2
		print(min_move)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = [int(x) for x in input().split()]
		even = 0
		odd = 0
		for i in range(N):
			if A[i] % 2 != i % 2:
				if i % 2 == 1:
					even += 1
				else:
					odd += 1
		if even != odd:
			print(-1)
		else:
			print(even)
main()


import math
t = int(input())
for w in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	(c1, c2) = (0, 0)
	for i in range(n):
		if l[i] % 2 == 0 and i % 2 == 1:
			c1 += 1
		elif l[i] % 2 == 1 and i % 2 == 0:
			c2 += 1
	if c1 != c2:
		print(-1)
	else:
		print(c1)


for _ in range(int(input())):
	x = int(input())
	data = list(map(int, input().split()))
	temp = [0] * x
	even = odd = 0
	counter = 0
	for i in range(x):
		if data[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if i % 2 != data[i] % 2:
			counter += 1
	if x % 2 == 0 and odd == even:
		print(counter // 2)
	elif x % 2 == 1 and even - 1 == odd:
		print(counter // 2)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = [int(s) for s in input().split()]
	a = 0
	b = 0
	for i in range(len(arr)):
		if i % 2 == 0 and arr[i] % 2 != 0:
			a += 1
		if i % 2 != 0 and arr[i] % 2 == 0:
			b += 1
	if a == b:
		print(a)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	co = 0
	ce = 0
	for i in range(0, len(a)):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				co += 1
		elif i % 2 == 1:
			if a[i] % 2 == 0:
				ce += 1
	if co == ce:
		print(co)
	else:
		print(-1)


testcases = int(input())
for num in range(0, testcases):
	size = int(input())
	x = list(map(int, input().split()))
	ew = ow = 0
	for i in range(0, size):
		if x[i] % 2 != i % 2:
			if x[i] % 2 == 0:
				ew += 1
			else:
				ow += 1
	if ew == ow:
		print(f'{ew}')
	else:
		print('-1')


def fun():
	n = int(input())
	lst = list(map(int, input().split()))
	cnt = [0, 0]
	for i in range(n):
		if i % 2 != lst[i] % 2:
			cnt[i % 2] += 1
	print(cnt[0] if cnt[0] == cnt[1] else -1)
for _ in range(int(input())):
	fun()


import sys

def swap(x, y, a):
	temp = a[x]
	a[x] = a[y]
	a[y] = temp
	return a

def solve():
	return None

def main():
	q = []
	for line in sys.stdin.readlines():
		q.append(line)
	for i in range(len(q)):
		q[i] = q[i].rstrip().split(' ')
		q[i] = [int(x) for x in q[i]]
	for i in range(2, len(q), 2):
		a = q[i]
		if len(a) % 2 == 1:
			e_a = len(a) // 2 + 1
		else:
			e_a = len(a) // 2
		o_a = len(a) // 2
		o = 0
		e = 0
		mismatch = 0
		for i in range(len(a)):
			if a[i] % 2 == 0:
				if i % 2 == 1:
					mismatch += 1
				e += 1
			else:
				if i % 2 == 0:
					mismatch += 1
				o += 1
		if mismatch == 0:
			print(0)
		elif o_a != o:
			print(-1)
		else:
			print(mismatch // 2)
main()


from math import ceil
t = int(input())
result = []
for i1 in range(t):
	n = int(input())
	array = [int(i2) for i2 in input().split()]
	(odd_count, even_count) = (0, 0)
	move_count = 0
	for i3 in range(n):
		parity_check = array[i3] % 2
		if i3 % 2 != parity_check:
			move_count += 1
		if parity_check:
			odd_count += 1
		else:
			even_count += 1
	if even_count == ceil(n / 2):
		result.append(move_count // 2)
	else:
		result.append(-1)
for i4 in result:
	print(i4)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = array()
	status = defaultdict(list)
	for i in range(n):
		if i % 2 != a[i] % 2:
			status[i % 2].append(a[i])
	if len(status[0]) != len(status[1]):
		print(-1)
	else:
		print(len(status[0]))


for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	x = 0
	y = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			if i % 2 == 0:
				x += 1
			else:
				y += 1
	print(x if x == y else '-1')


n = int(input())
while n > 0:
	m = int(input())
	l = []
	l = input().split(' ')
	l = [int(i) for i in l]
	l1 = []
	l1 = [j % 2 for j in l]
	res1 = l1.count(1)
	l2 = [j % 2 for j in range(0, len(l1))]
	res2 = l2.count(1)
	c = 0
	if res1 == res2:
		for k in range(0, len(l)):
			if l1[k] == l2[k] and l1[k] == 1:
				c = c + 1
			else:
				continue
		print(res1 - c)
	else:
		print('-1')
	n = n - 1


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	par = []
	for i in range(0, n, 2):
		if l[i] % 2 != 0:
			par.append(i)
	for i in range(1, n, 2):
		if l[i] % 2 == 0:
			par.append(i)
	if len(par) == 0:
		print(0)
	elif len(par) % 2 == 1:
		print(-1)
	else:
		count = 0
		for i in range(len(par)):
			if par[i] % 2 == 0:
				count += 1
		if count == len(par) // 2:
			print(count)
		else:
			print(-1)


a = int(input())
for _ in range(a):
	b = int(input())
	t = list(map(int, input().split()))
	hi = len(t)
	c = [i % 2 for i in t]
	if hi % 2 == 0 and c.count(1) != c.count(0):
		print(-1)
		continue
	if hi % 2 != 0 and c.count(1) + 1 != c.count(0):
		print(-1)
		continue
	count = 0
	for i in range(len(t)):
		if i % 2 != t[i] % 2:
			count += 1
	print(count // 2)


import math
for w in range(int(input())):
	n = int(input())
	let = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if let[i] % 2 == 0 and i % 2 != 0:
			even += 1
		elif let[i] % 2 != 0 and i % 2 == 0:
			odd += 1
	print(even if even == odd else -1)


for _ in range(int(input())):
	n = int(input())
	arr = map(int, input().split())
	ev_f = 0
	odd_f = 0
	for (i, val) in enumerate(arr):
		if i % 2 == 0 and val % 2 != 0:
			ev_f += 1
		elif i % 2 != 0 and val % 2 == 0:
			odd_f += 1
	if ev_f == odd_f:
		print(ev_f)
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	evePar = []
	oddPar = []
	for i in range(n):
		if i % 2 and (not a[i] % 2):
			oddPar.append(i)
		elif not i % 2 and a[i] % 2:
			evePar.append(i)
	if len(evePar) == len(oddPar):
		print(str(len(evePar)))
	else:
		print(str(-1))


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	n = getInt()
	a = getList()
	d = [0, 0]
	for i in range(n):
		if a[i] % 2 == i % 2:
			continue
		d[a[i] % 2] += 1
	if d[0] == d[1]:
		print(d[0])
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = 0
	b = 0
	l = list(map(int, input().split()))
	for j in range(n):
		if j % 2 == 1 and l[j] % 2 == 0:
			a += 1
		elif j % 2 == 0 and l[j] % 2 == 1:
			b += 1
	if a == b:
		print(a)
	else:
		print(-1)


for _ in range(int(input())):
	(n, rez) = (int(input()), [0, 0])
	for (i, a_i) in enumerate(map(int, input().split())):
		rez[i % 2] += a_i % 2 != i % 2
	print([-1, sum(rez) // 2][rez[0] == rez[-1]])


T = int(input())
for _ in range(T):
	N = int(input())
	arr = list(map(int, input().rstrip().split()))
	dif = [0, 0]
	for i in range(N):
		if arr[i] % 2 != i % 2:
			dif[i % 2] += 1
	if dif[0] == dif[1]:
		print(dif[0])
	else:
		print('-1')


for r in [*open(0)][2::2]:
	j = [int(x) % 2 for x in r.split()]
	print((sum((i % 2 ^ x for (i, x) in enumerate(j))) // 2, -1)[sum(j) != len(j) // 2])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	even = 0
	odd = 0
	for x in range(n):
		if x % 2 == 0:
			if a[x] % 2 != 0:
				even += 1
		elif a[x] % 2 != 1:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	ai = list(map(int, input().split()))
	num = 0
	num2 = 0
	for i in range(n):
		if i % 2 == 0:
			num += (i + ai[i]) % 2
		else:
			num2 += (i + ai[i]) % 2
	if num != num2:
		print(-1)
	else:
		print(num)


def search(x, key, i):
	lo = i
	hi = len(x)
	for t in range(lo, hi):
		if x[t] % 2 == key and x[i] % 2 == t % 2:
			return t
	return -1
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	flag = 1
	for i in range(n):
		if i % 2 == x[i] % 2:
			continue
		else:
			flag = -1
			lo = i
			break
	if flag == 1:
		print(0)
	else:
		flg = 1
		c = 0
		for i in range(lo, n):
			if i % 2 == x[i] % 2:
				continue
			else:
				c += 1
				pos = search(x, i % 2, i)
				if pos == -1:
					flg = -1
					break
				(x[i], x[pos]) = (x[pos], x[i])
		if flg == -1:
			print(-1)
		else:
			print(c)


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = 0
	for (i, x) in enumerate(arr):
		if arr[i] % 2 == i % 2:
			continue
		flg = False
		for (j, y) in enumerate(arr):
			if i < j and i % 2 == arr[j] % 2 and (arr[j] % 2 != j % 2):
				ans += 1
				(arr[i], arr[j]) = (arr[j], arr[i])
				flg = True
				break
		if flg == False:
			ans = -1
			break
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ch = len(l) // 2 + len(l) % 2
	nch = len(l) // 2
	depos = 0
	for j in range(len(l)):
		if j % 2 != l[j] % 2:
			depos += 1
		if l[j] % 2 == 0:
			ch -= 1
		else:
			nch -= 1
	if ch == 0 and nch == 0:
		print(depos // 2)
	else:
		print(-1)


T = int(input())
for t in range(T):
	N = int(input())
	arr = [int(x) for x in input().split(' ')]
	badodd = 0
	badeven = 0
	for i in range(N):
		if i % 2 != arr[i] % 2:
			if i % 2:
				badodd += 1
			else:
				badeven += 1
	if badeven != badodd:
		print(-1)
	else:
		print(badeven)


import math

def BuubleSort(n, a):
	odd = 0
	even = 0
	for i in range(0, n):
		if i % 2 != 0 and a[i] % 2 == 0:
			even += 1
		elif i % 2 == 0 and a[i] % 2 != 0:
			odd += 1
	if odd != even:
		return -1
	else:
		return odd

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		l = list(map(int, input().split()))
		ans = BuubleSort(n, l)
		print(ans)
main()


t = input()
testcase = int(t)
for i in range(testcase):
	t = input()
	n = int(t)
	s = input()
	temp = s.split()
	numbers = [int(i) for i in temp]
	mismatch = 0
	indexEven = 0
	arrayEven = 0
	for i in range(n):
		if i % 2 != numbers[i] % 2:
			mismatch += 1
			if i % 2 == 0:
				indexEven += 1
			if numbers[i] % 2 == 0:
				arrayEven += 1
	if indexEven == arrayEven:
		print(int(mismatch / 2))
	else:
		print(-1)


t = int(input())
for dud in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	bad1 = 0
	bad2 = 0
	for idx in range(len(arr)):
		if idx % 2 == 1 and idx % 2 != arr[idx] % 2:
			bad1 += 1
		if idx % 2 == 0 and idx % 2 != arr[idx] % 2:
			bad2 += 1
	if bad1 != bad2:
		print(-1)
	else:
		print(bad1)


t = int(input())
res = []
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	even_w = 0
	odd_w = 0
	for i in range(n):
		if a[i] % 2 != i % 2 and a[i] % 2 == 0:
			even_w += 1
		elif a[i] % 2 != i % 2 and a[i] % 2 == 1:
			odd_w += 1
	if odd_w == even_w:
		res.append(odd_w)
	else:
		res.append(-1)
for x in res:
	print(x)


t = int(input())
a = []
for i in range(t):
	n = int(input())
	s = [int(i) for i in input().split()]
	(numc, numn) = (0, 0)
	for i in range(n):
		if i % 2 != s[i] % 2:
			if s[i] % 2 == 0:
				numc += 1
			elif s[i] % 2 != 0:
				numn += 1
	if numc == numn:
		a.append(numc)
	else:
		a.append(-1)
for i in a:
	print(i)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	p = list(map(int, list('0' * n)))
	for j in range(n):
		if j % 2 == 1:
			p[j] = 1
	s = 0
	t = 0
	for k in range(n):
		if l[k] % 2 != p[k]:
			if l[k] % 2 == 1 and p[k] == 0:
				s += 1
			elif l[k] % 2 == 0 and p[k] == 1:
				t += 1
	if s == t:
		print(int(t))
	else:
		print(-1)


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split(' ')))
	evenCount = 0
	oddCount = 0
	for i in range(len(a)):
		if i % 2 == 0 and a[i] % 2 != 0:
			evenCount += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			oddCount += 1
	if evenCount != oddCount:
		print(-1)
	else:
		print(oddCount)


import sys
import threading

def get_numbers():
	return map(int, sys.stdin.readline().strip().split())

def find_path(graph, start, vis):
	vis[start] = 1
	if not vis[graph[start]]:
		find_path(graph, graph[start], vis)

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = list(get_numbers())
		odd = 0
		even = 0
		for num in arr:
			if num % 2 == 0:
				even += 1
			else:
				odd += 1
		if n % 2 == 0 and (not even == odd):
			print(-1)
		elif n % 2 == 1 and (not even == odd + 1):
			print(-1)
		else:
			moves = 0
			for (ind, num) in enumerate(arr):
				if ind % 2 != num % 2:
					moves += 1
			print(moves // 2)
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
main_thread = threading.Thread(target=main)
main_thread.start()
main_thread.join()


for _ in range(int(input())):
	size = int(input())
	lis = list(map(lambda x: int(x) % 2, input().split()))
	ones = lis.count(1)
	count = 0
	if ones == size // 2:
		for x in range(size):
			if x % 2 != lis[x]:
				count += 1
		print(count // 2)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	num = 0
	odd = 0
	s = list(map(int, input().split()))
	for (_, i) in enumerate(s):
		if i % 2 != 0:
			num += 1
			if _ % 2 == 0:
				odd += 1
	if num != n // 2:
		print('-1')
	else:
		print(odd)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	badEven = 0
	badOdd = 0
	for i in range(n):
		if i % 2 != a[i] % 2 and i % 2 == 0:
			badEven += 1
		elif i % 2 != a[i] % 2 and i % 2 == 1:
			badOdd += 1
	if badEven == badOdd:
		print(badEven)
	else:
		print(-1)


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		e = list(filter(lambda x: x % 2 == 0, a))
		b = enumerate(a)
		e1 = list(filter(lambda x: x[0] % 2 == 1 and x[1] % 2 == 1, b))
		if n - len(e) == n // 2:
			print(n - len(e) - len(e1))
		else:
			print(-1)
main()


t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	(eve, odd, i) = (0, 0, 0)
	while i < n:
		if i % 2 == 0 and a[i] % 2 != 0:
			odd += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			eve += 1
		i += 1
	if odd == eve:
		print(odd)
	else:
		print(-1)


def evenArray(arr, n):
	ep = 0
	op = 0
	for i in range(n):
		if arr[i] % 2 != i % 2:
			if i % 2 == 0:
				ep += 1
			else:
				op += 1
	if ep == op:
		return ep
	else:
		return -1
ans = []
n = int(input())
for i in range(n):
	m = int(input())
	l = input()
	l = l.split(' ')
	for i in range(len(l)):
		l[i] = int(l[i])
	ans.append(evenArray(l, m))
for i in ans:
	print(i)


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	(e, o) = (0, 0)
	for i in range(a):
		if i % 2 != b[i] % 2:
			if b[i] % 2 == 0:
				e += 1
			else:
				o += 1
	if e != o:
		print('-1')
	else:
		print(o)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even = 0
	odd = 0
	for j in range(n):
		if a[j] % 2 == 0:
			even += 1
		elif a[j] % 2 == 1:
			odd += 1
	flag = False
	if n % 2 == 1:
		if odd == n // 2 and even == n // 2 + 1:
			flag = True
		else:
			print(-1)
	elif n % 2 == 0:
		if odd == n // 2 and even == n // 2:
			flag = True
		else:
			print(-1)
	if flag:
		even = 0
		odd = 0
		for j in range(n):
			if j % 2 == 0:
				if a[j] % 2 != j % 2:
					even += 1
			elif j % 2 == 1:
				if a[j] % 2 != j % 2:
					odd += 1
		print(odd)


t = int(input())
result_lst = list()

def isGood(lst, n):
	mismatch01 = 0
	mismatch10 = 0
	for i in range(n):
		if i % 2 == 0 and lst[i] % 2 == 1:
			mismatch01 += 1
		elif i % 2 == 1 and lst[i] % 2 == 0:
			mismatch10 += 1
	if mismatch10 == mismatch01:
		return mismatch10
	else:
		return -1
for test_case in range(t):
	n = int(input())
	num_lst = [int(i) for i in input().split()][:n]
	result_lst.append(isGood(num_lst, n))
for i in result_lst:
	print(i)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	o = 0
	e = 0
	ec = 0
	oc = 0
	for i in l:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
	if n % 2 == 0 and e != o or (n & 1 and e != o + 1):
		print('-1')
	else:
		for i in range(n):
			if i % 2 == 0 and l[i] % 2 != 0:
				oc += 1
		print(oc)


for _ in range(int(input())):
	n = int(input())
	(ec, oc) = (0, 0)
	l = list(map(int, input().split()))
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				ec += 1
		elif l[i] % 2 == 0:
			oc += 1
	if oc == ec:
		print(oc)
	else:
		print(-1)


import math
m = int(input())
for t in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	y = 0
	for i in range(n):
		if a[i] % 2 == 0:
			x = x + 1
		if a[i] % 2 == 0 and i % 2 != 0:
			y = y + 1
	if x == math.ceil(n / 2):
		print(y)
	else:
		print(-1)


t = int(input())
for case in range(t):
	n = int(input())
	List = [int(j) for j in input().split(' ')]
	count = 0
	count_1 = 0
	for i in range(n):
		if i % 2 != List[i] % 2 and List[i] % 2 == 0:
			count += 1
		elif i % 2 != List[i] % 2 and List[i] % 2 == 1:
			count_1 += 1
	if count == count_1:
		print(count)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	s = map(int, input().split())
	remain = [0, 0]
	for (i, x) in enumerate(s):
		i %= 2
		x %= 2
		if i != x:
			remain[i] += 1
	if remain[0] != remain[1]:
		print(-1)
	else:
		print(remain[0])


t = 1
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	(wrongodd, wrongeven) = (0, 0)
	for (i, el) in enumerate(a):
		if i % 2 == 1 and el % 2 == 0:
			wrongeven += 1
		elif i % 2 == 0 and el % 2 == 1:
			wrongodd += 1
	if wrongodd == wrongeven:
		print(wrongodd)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	A = getInts()
	(type1, type2) = (0, 0)
	for (i, a) in enumerate(A):
		if i % 2 == 0 and a % 2 == 1:
			type1 += 1
		if i % 2 == 1 and a % 2 == 0:
			type2 += 1
	if type1 != type2:
		return -1
	return type1
for _ in range(getInt()):
	print(solve())


def ans(n, arr):
	correct = []
	for i in range(n):
		if arr[i] % 2 == 0 and i % 2 == 0:
			correct.append(i)
		if arr[i] % 2 == 1 and i % 2 == 1:
			correct.append(i)
	even = []
	odd = []
	for i in range(n):
		if i in correct:
			continue
		elif arr[i] % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	if len(even) == len(odd):
		return len(even)
	return -1
t = int(input())
L = []
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	L.append(ans(n, arr))
for l in L:
	print(l)


t = int(input())
while t:
	n = input()
	a = input()
	a = [int(x) for x in a.split()]
	k0 = 0
	k1 = 0
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			if a[i] % 2 == 0:
				k0 += 1
			else:
				k1 += 1
	if k1 == k0:
		print(k0)
	else:
		print('-1')
	t -= 1


I = lambda : list(map(int, input().split(' ')))
J = lambda : int(input())
for _ in range(J()):
	n = J()
	lst = I()
	even = 0
	odd = 0
	for i in range(len(lst)):
		if lst[i] % 2 == 0 and i % 2 == 1:
			even += 1
		elif lst[i] % 2 == 1 and i % 2 == 0:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = 0
	(el, ol) = ((n + 1) // 2, n - (n + 1) // 2)
	(e, o) = (0, 0)
	f = 0
	for i in range(n):
		x = i % 2
		y = l[i] % 2
		if y == 0:
			e += 1
		else:
			o += 1
		if x != y:
			m += 1
		if e > el or o > ol:
			f = 1
			break
	if f == 0 and m % 2 == 0:
		print(m // 2)
	else:
		print(-1)


t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	even = 0
	need_odd = 0
	need_even = 0
	for i in range(n):
		num = a[i]
		if i % 2 != num % 2:
			if i % 2 == 1:
				need_odd += 1
			else:
				need_even += 1
	if need_even != need_odd:
		print(-1)
	else:
		print(need_odd)


t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(oddi, eveni) = (0, 0)
	for i in range(n):
		if a[i] % 2 != i % 2 and i % 2:
			oddi += 1
		elif a[i] % 2 != i % 2 and i % 2 == 0:
			eveni += 1
	if (oddi or eveni) and oddi != eveni:
		print(-1)
	elif oddi == eveni:
		print(oddi)


T = int(input())
for i in range(T):
	N = int(input())
	count = 0
	count1 = 0
	lst = list(map(int, input().split()))
	for i in range(0, len(lst), 2):
		if lst[i] % 2 != 0:
			count += 1
	for i in range(1, len(lst), 2):
		if lst[i] % 2 == 0:
			count1 += 1
	if count == count1:
		print(count)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ch = 0
	nech = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			nech += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			ch += 1
	if ch != nech:
		print(-1)
	else:
		print(ch)


tc = int(input())
for i in range(tc):
	n = int(input())
	arr = list(map(int, input().split()))
	(odd, even) = (0, 0)
	for x in range(n):
		if x & 1 != arr[x] & 1:
			if x & 1:
				odd += 1
			else:
				even += 1
	if odd != even:
		print(-1)
	else:
		print(odd)


case = int(input())
while case > 0:
	arr_len = int(input())
	arr = input().split()
	even = 0
	odd = 0
	for i in range(len(arr)):
		if i % 2 == 0 and int(arr[i]) % 2 != 0:
			odd += 1
		if i % 2 != 0 and int(arr[i]) % 2 == 0:
			even += 1
	if even != odd:
		print(-1)
	else:
		print(even)
	case -= 1


from collections import deque, defaultdict
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7

def readInts():
	return list(map(int, input().split()))

def I():
	return int(input())
for i in range(I()):
	n = I()
	A = readInts()
	mustodd = n // 2
	musteven = n - mustodd
	odd = 0
	even = 0
	for a in A:
		if a & 1:
			odd += 1
		else:
			even += 1
	if not (musteven == even and mustodd == odd):
		print('-1')
	else:
		cnt = 0
		for i in range(n):
			if i % 2 == 0:
				if A[i] % 2:
					cnt += 1
		print(cnt)


t = int(input())
for w in range(t):
	n = int(input())
	a = 0
	b = 0
	s = input().split()
	for h in range(n):
		if int(s[h]) % 2 != h % 2:
			if h % 2 == 1:
				a += 1
			else:
				b += 1
	if a == b:
		print(a)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().rstrip().split()))
	zer = 0
	one = 0
	l = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			l += 1
			if i % 2 == 0:
				zer += 1
			else:
				one += 1
	if l % 2 == 0:
		if zer == one:
			print(l // 2)
		else:
			print('-1')
	else:
		print('-1')


n = int(input())
for i in range(n):
	sum = eve = od = 0
	n1 = int(input())
	arr = list(map(int, input().split()))
	for i in range(n1):
		if i % 2 != arr[i] % 2:
			sum = sum + 1
			if arr[i] % 2 == 0:
				eve = eve + 1
			else:
				od = od + 1
	if sum == 0:
		print(0)
	elif sum % 2 != 0:
		print(-1)
	elif sum % 2 == 0 and eve == od:
		print(int(sum / 2))
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	pcnt = 0
	ocnt = 0
	ecnt = 0
	for i in range(n):
		if i & 1 and a[i] & 1 or (i & 1 == 0 and a[i] & 1 == 0):
			pcnt += 1
		elif a[i] & 1:
			ocnt += 1
		else:
			ecnt += 1
	ans = 0
	if ocnt == ecnt:
		ans += ocnt
	else:
		ans = -1
	print(ans)


t = int(input())
if t >= 1 and t <= pow(10, 4):
	while t > 0:
		x = int(input())
		if x >= 1 and x <= 40:
			n = []
			n.append(map(int, input().split()))
			parni = 0
			neparni = 0
			position = -1
			Fparn = 0
			Fnep = 0
			for i in list(n[0]):
				position += 1
				if i % 2 == 0:
					parni += 1
					if position % 2 != 0:
						Fparn += 1
				else:
					neparni += 1
					if position % 2 == 0:
						Fnep += 1
			if Fparn == Fnep:
				print(Fparn)
			else:
				print(-1)
			n.clear()
		t -= 1


try:
	t = int(input())
	for i in range(t):
		n = int(input())
		(count, count1) = (0, 0)
		l = list(map(int, input().split()))
		for j in range(n):
			if j % 2 == 0:
				if l[j] % 2 != 0:
					count += 1
			elif l[j] % 2 == 0:
				count1 += 1
		if count == count1:
			print(count)
		else:
			print(-1)
except:
	pass


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for i in range(INT()):
	n = INT()
	arr = LIST()
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			odd += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			even += 1
	if even == odd:
		print(odd)
	else:
		print(-1)


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for __ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	(o, e) = (0, 0)
	p = 0
	for i in range(n):
		if l[i] % 2 != i % 2:
			if l[i] % 2 == 0:
				e += 1
			else:
				o += 1
			p += 1
	if o == e:
		print(o)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	index_mod = []
	value_mod = []
	swaps = 0
	for j in range(0, n):
		index_mod.append(j % 2)
		value_mod.append(arr[j] % 2)
	for j in range(0, n):
		if index_mod[j] == value_mod[j]:
			continue
		else:
			flag = 0
			for k in range(j + 1, n):
				if value_mod[k] == index_mod[j] and value_mod[k] != index_mod[k]:
					(value_mod[j], value_mod[k]) = (value_mod[k], value_mod[j])
					swaps += 1
					flag = 1
					break
				else:
					flag = 0
			if flag == 0:
				print(-1)
				break
	else:
		print(swaps)


import sys
t = int(input())
while t > 0:
	n = sys.stdin.readline()
	n = int(n)
	arr = []
	input = sys.stdin.readline()
	data = list(map(int, input.split()))
	arr = data
	evens = 0
	odds = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			evens += 1
		else:
			odds += 1
	if not 0 <= evens - odds <= 1:
		print(-1)
	else:
		nos = 0
		for i in range((n + 1) // 2):
			if arr[2 * i] % 2 != 0:
				nos += 1
		print(nos)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	e = 0
	o = 0
	for x in range(n):
		if li[x] % 2 == 0 and x % 2 != 0:
			e += 1
		elif li[x] % 2 != 0 and x % 2 == 0:
			o += 1
	if o == e:
		print(o)
	else:
		print(-1)


t = int(input())
for I in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	(ze, on) = (0, 0)
	for i in range(len(a)):
		if i % 2 == a[i] % 2:
			continue
		else:
			par = i % 2
			if par == 0:
				ze += 1
			else:
				on += 1
	if ze == 0 and on == 0:
		print(0)
	elif ze == on:
		print(ze)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	for i in range(n):
		if a[i] % 2 != i % 2:
			l.append(a[i])
	oc = sum((i % 2 for i in l))
	ec = len(l) - oc
	if oc != ec:
		print(-1)
		continue
	else:
		print(oc)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	l = I()
	o = z = 0
	cz = 0
	for i in range(n):
		l[i] = l[i] % 2
		cz += l[i] == 0
		o += l[i] == 1 and i % 2 == 0
		z += l[i] == 0 and i % 2
	if cz != (n + 1) // 2:
		print(-1)
	else:
		print(min(o, z))


n = int(input())
s1 = 0
s2 = 0
for i in range(n):
	a = int(input())
	sp = list(map(int, input().split()))
	for i in range(len(sp)):
		if i % 2 == 0 and sp[i] % 2 == 1:
			s1 += 1
		if i % 2 == 1 and sp[i] % 2 == 0:
			s2 += 1
	if s1 == s2:
		print(s1)
	else:
		print(-1)
	s1 = 0
	s2 = 0


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(c, x, y) = (0, 0, 0)
	for i in range(n):
		if not (i % 2 == 0 and a[i] % 2 == 0 or (i % 2 != 0 and a[i] % 2 != 0)):
			c += 1
		if a[i] % 2 == 0:
			x += 1
		else:
			y += 1
	if x == y or x - 1 == y:
		print(c // 2)
	else:
		print(-1)


import sys, math, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
from decimal import Decimal
from fractions import Fraction

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 20
mod = 10 ** 9 + 7
for i in range(int(data())):
	n = int(data())
	a = mdata()
	o = e = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if a[i] % 2 == 0:
				e += 1
			else:
				o += 1
	if e != o:
		out(-1)
	else:
		out(e)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	d = {'eo': 0, 'oe': 0}
	for i in range(n):
		if i % 2 != 0 and a[i] % 2 == 0:
			d['oe'] += 1
		elif i % 2 == 0 and a[i] % 2 != 0:
			d['eo'] += 1
	if d['eo'] != d['oe']:
		print(-1)
	else:
		print(d['eo'])
	return

def main():
	t = int(input())
	for i in range(t):
		solve()
	return
main()


n1 = int(input())
for x in range(n1):
	n2 = int(input())
	l1 = input().split(' ')
	(count1, count2) = (0, 0)
	for y in range(n2):
		l1[y] = int(l1[y])
	for y in range(n2):
		if y & 1 != l1[y] & 1:
			if y & 1:
				count1 += 1
			else:
				count2 += 1
	if count1 == count2:
		print(count1)
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	c = [0, 0]
	for i in range(n):
		if l[i] % 2 != i % 2:
			c[i % 2] += 1
	if c[0] == c[1]:
		print(c[0])
	else:
		print(-1)
	t = t - 1


T = int(input())

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(len(arr)):
		if arr[i] % 2 == 0:
			arr[i] = 0
			even += 1
		else:
			arr[i] = 1
			odd += 1
	if even != odd:
		if even != odd + 1:
			return -1
	actual_arr = [0] * n
	for i in range(1, len(arr), 2):
		actual_arr[i] = 1
	if actual_arr == arr:
		return 0
	c = 0
	for i in range(n):
		if arr[i] != actual_arr[i]:
			c += 1
	return c // 2
for i in range(T):
	print(main())


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	od = 0
	ev = 0
	ans = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			ev += 1
		elif i % 2 != 0 and a[i] % 2 != 1:
			od += 1
	if od == ev:
		print(od)
	else:
		print(-1)


x = int(input())
l = []
for j in range(x):
	y = int(input())
	m = []
	z = str(input()).split(' ')
	for i in range(0, len(z), 1):
		a = z[i]
		a = int(a)
		a = a % 2
		m.append(a)
	ze = m.count(0)
	one = m.count(1)
	onein = len(m) // 2
	zein = len(m) - onein
	if one != onein or ze != zein:
		l.append(-1)
		continue
	else:
		count = 0
		for i in range(len(m)):
			a = m[i]
			if i % 2 != a:
				count = count + 1
		count = count // 2
		l.append(count)
for i in l:
	print(i)


def eligible(n, ec, oc):
	if n % 2 == 0 and ec == oc:
		return 1
	elif n % 2 != 0 and ec == oc + 1:
		return 1
	else:
		return 0
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().strip().split()))[:n]
	ec = oc = c = 0
	for i in l:
		if i % 2 == 0:
			ec += 1
		else:
			oc += 1
	if eligible(n, ec, oc):
		for i in range(0, n, 2):
			if l[i] % 2 != 0:
				c += 1
	else:
		c = -1
	print(c)


def main():
	t = int(input())
	while t:
		n = int(input())
		li = list(map(int, input().split()))
		(count1, count2) = (0, 0)
		for i in range(len(li)):
			if i % 2 == 0 and li[i] % 2 != 0:
				count1 += 1
			if i % 2 == 1 and li[i] % 2 != 1:
				count2 += 1
		if count1 == count2:
			print(count1)
		else:
			print(-1)
		t -= 1
main()


t = int(input())
while t > 0:
	t -= 1
	_ = input()
	li = list(map(int, input().split()))
	odd = []
	even = []
	for i in range(0, len(li), 2):
		if li[i] % 2 != 0:
			even.append(li[i])
	for i in range(1, len(li), 2):
		if li[i] % 2 == 0:
			odd.append(li[i])
	if len(odd) == len(even):
		print(len(odd))
	else:
		print(-1)


def solve():
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	o = 0
	e = 0
	for i in range(n):
		x = i % 2
		y = a[i] % 2
		if x != y:
			if a[i] % 2 != 0:
				o += 1
			else:
				e += 1
	if e == o:
		print(e)
	else:
		print(-1)
t = int(input())
for i in range(1, t + 1):
	solve()


ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
for _ in range(ii()):
	n = ii()
	a = il()
	L = 0
	c = 0
	d = 0
	for i in range(0, n):
		if i % 2 != a[i] % 2 and i % 2 == 0:
			c = c + 1
		elif i % 2 != a[i] % 2 and i % 2 != 0:
			d = d + 1
	if c == d:
		print(c)
		P = 0
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	count1 = 0
	count2 = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			count1 = count1 + 1
		else:
			count2 = count2 + 1
	if n % 2 != 0:
		if count1 != n // 2 + 1 and count2 != n // 2:
			print(-1)
		else:
			r = 0
			for i in range(n):
				p1 = i % 2
				q1 = arr[i] % 2
				if p1 != q1:
					r = r + 1
			print(r // 2)
	elif n % 2 == 0:
		if count1 != n // 2 and count2 != n // 2:
			print(-1)
		else:
			r = 0
			for i in range(n):
				p1 = i % 2
				q1 = arr[i] % 2
				if p1 != q1:
					r = r + 1
			print(r // 2)


sz = 0
sz = int(input())
t = 0
arr = []

def Petya(sz):
	for i in range(sz):
		even = 0
		odd = 0
		t = int(input())
		arr = list(map(int, input().split()))
		for j in range(t):
			if j % 2 == 0 and arr[j] % 2 != 0:
				even += 1
			elif j % 2 == 1 and arr[j] % 2 != 1:
				odd += 1
		if even == odd:
			print(even)
		else:
			print(-1)
Petya(sz)


x = int(input())
for i in range(x):
	n = int(input())
	l = list(map(int, input().split()))
	counteven = 0
	countodd = 0
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] % 2 == 1:
				counteven += 1
		elif l[i] % 2 == 0:
			countodd += 1
	if counteven == countodd:
		print(counteven)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	unpaired_even = 0
	unpaired_odd = 0
	for i in range(0, n, 2):
		if a[i] % 2 != 0:
			unpaired_even += 1
	for i in range(1, n, 2):
		if a[i] % 2 == 0:
			unpaired_odd += 1
	if unpaired_odd != unpaired_even:
		print(-1)
	else:
		print(unpaired_even)


import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	odd = math.floor(len(arr) / 2)
	even = 0
	neven = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			even += 1
			if i % 2 == 1:
				neven += 1
	if n - odd != even:
		print(-1)
	else:
		print(neven)


from sys import stdin
a = int(stdin.readline())
for k in range(0, a):
	b = int(stdin.readline())
	c = list(map(int, stdin.readline().split()))
	OE = 0
	EO = 0
	EE = 0
	OO = 0
	for t in range(0, b):
		if t % 2 == 0:
			if c[t] % 2 == 0:
				EE += 1
			else:
				EO += 1
		elif t % 2 == 1:
			if c[t] % 2 == 1:
				OO += 1
			else:
				OE += 1
	if EO == OE:
		print(EO)
	else:
		print(-1)


t = int(input())
for i in range(0, t):
	n = int(input())
	steps = 0
	lst1 = []
	lst2 = []
	lst = list((int(num) for num in input().split()))[:n]
	for j in range(0, n):
		lst1.append(lst[j] % 2)
		lst2.append(j % 2)
	for j in range(0, n):
		if lst1[j] != lst2[j]:
			steps += 1
	if lst1.count(0) == lst2.count(0):
		if steps % 2 == 0:
			print(int(steps / 2))
		elif steps == 0:
			print('0')
		else:
			print('-1')
	else:
		print('-1')


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	n = ii1()
	arr = iia()
	even = odd = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if arr[i] % 2 != 0:
				odd += 1
			else:
				even += 1
	if even == odd:
		print(even)
	else:
		print(-1)


tcs = int(input())
for tc in range(tcs):
	n = int(input())
	a = list(map(int, input().split()))
	we = wo = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			we += 1
		if i % 2 == 1 and a[i] % 2 != 1:
			wo += 1
	if we == wo:
		print(we)
	else:
		print(-1)


t = int(input())
while t:
	n = int(input())
	x = 0
	y = 0
	a = list(map(int, input().rstrip().split()))
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			x += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			y += 1
	if x == y:
		print(x)
	else:
		print(-1)
	t -= 1


test = int(input())
for i in range(test):
	n = int(input())
	arr = [int(i) for i in input().split()]
	type1 = 0
	type2 = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 == 1:
			type1 += 1
		elif i % 2 == 1 and arr[i] % 2 == 0:
			type2 += 1
	if type1 != type2:
		print(-1)
	else:
		print(type1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	count = 0
	odd = 0
	even = 0
	for j in range(n):
		index_parity = j % 2
		element_parity = a[j] % 2
		if index_parity != element_parity:
			if index_parity == 0:
				even += 1
			else:
				odd += 1
	if odd == even:
		print(int(odd))
	else:
		print(-1)


from collections import defaultdict
t = int(input())
res = []
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	d = defaultdict(list)
	odd = []
	even = []
	count = 0
	for i in range(n):
		if not i % 2 and arr[i] % 2:
			odd.append(arr[i])
			d[arr[i]].append(i)
		elif i % 2 and (not arr[i] % 2):
			even.append(arr[i])
			d[arr[i]].append(i)
	for i in range(n):
		if not i % 2:
			if arr[i] % 2:
				if even:
					x = even.pop()
					ind = d[x].pop()
					(arr[i], arr[ind]) = (arr[ind], arr[i])
					count += 1
					del odd[odd.index(arr[ind])]
					del d[arr[ind]][d[arr[ind]].index(i)]
				else:
					count = -1
					break
		elif not arr[i] % 2:
			if odd:
				x = odd.pop()
				ind = d[x].pop()
				(arr[i], arr[ind]) = (arr[ind], arr[i])
				count += 1
				del even[even.index(arr[ind])]
				del d[arr[ind]][d[arr[ind]].index(i)]
			else:
				count = -1
				break
	res.append(count)
for i in res:
	print(i)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
while t > 0:
	ind = inp()
	foo = inlt()
	odd = 0
	evn = 0
	for (i, item) in enumerate(foo):
		if i % 2 != item % 2:
			if i % 2 == 0:
				odd += 1
			else:
				evn += 1
	if odd == evn:
		print(odd)
	else:
		print(-1)
	t -= 1


t = int(input())
taille = []
tab = []
for i in range(0, t):
	a = []
	taille.append(int(input()))
	ch = str(input())
	x = ch.split(' ')
	tab.append(x)
for i in range(0, t):
	not_pair = 0
	not_impaire = 0
	for j in range(0, taille[i]):
		if not int(tab[i][j]) % 2 == j % 2 and j % 2 == 0:
			not_pair += 1
		elif not int(tab[i][j]) % 2 == j % 2 and j % 2 == 1:
			not_impaire += 1
	if not_pair == not_impaire:
		print(not_pair)
	else:
		print('-1')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ce = 0
	co = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			ce += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			co += 1
	if ce == co:
		print(ce)
	else:
		print('-1')


T = int(input())
for t in range(T):
	N = int(input())
	A = [int(_) for _ in input().split()]
	(badE, badO) = (0, 0)
	for (i, el) in enumerate(A):
		if el % 2 != i % 2:
			if i % 2:
				badO += 1
			else:
				badE += 1
	if badO != badE:
		print(-1)
	else:
		print(badO)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	evenBad = 0
	oddBad = 0
	for (i, x) in enumerate(A):
		if i % 2 != x % 2:
			if i % 2 == 0:
				evenBad += 1
			else:
				oddBad += 1
	if evenBad != oddBad:
		return -1
	return evenBad
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = []
	b = []
	c = []
	c1 = []
	for i in range(n):
		a.append(i % 2)
		b.append(l[i] % 2)
	for j in range(n):
		c.append(a[j] - b[j])
		c1.append(abs(a[j] - b[j]))
	if sum(c) != 0:
		print('-1')
	else:
		print(sum(c1) // 2)


for u in range(int(input())):
	n = int(input())
	x = [int(w) for w in input().split()]
	a = 0
	b = 0
	for i in range(n):
		if x[i] % 2 != i % 2 and i % 2 == 0:
			a += 1
		if x[i] % 2 != i % 2 and i % 2 == 1:
			b += 1
	if a == b:
		print((a + b) // 2)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	eg = 0
	og = 0
	for i in range(len(a)):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				eg += 1
		elif a[i] % 2 == 0:
			og += 1
	if eg != og:
		print(-1)
	else:
		print(eg)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	(even, odd) = (0, 0)
	for (ind, el) in enumerate(a):
		counter = 0
		if ind % 2 == 1 and el % 2 == 0:
			even += 1
		elif ind % 2 == 0 and el % 2 == 1:
			odd += 1
	if even == odd:
		print(even)
	else:
		print('-1')


def ii():
	return int(input())

def si():
	return input()

def li():
	return list(map(int, input().split()))

def iwl():
	return map(int, input().split())
t = ii()
for i in range(t):
	n = ii()
	l = li()
	c = 0
	eo = 0
	oe = 0
	for i in range(n):
		if l[i] % 2 != i % 2:
			if l[i] % 2 == 0 and i % 2 != 0:
				eo += 1
			elif l[i] % 2 != 0 and i % 2 == 0:
				oe += 1
	if oe == eo:
		print(oe)
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	a = [int(x) for x in input().split()]
	if len(a) == 1:
		if a[0] % 2 == 0:
			print(0)
		else:
			print(-1)
	else:
		ce = 0
		co = 0
		for i in range(0, len(a), 2):
			if a[i] % 2 != 0:
				ce = ce + 1
		for i in range(1, len(a), 2):
			if a[i] % 2 == 0:
				co = co + 1
		if ce == co:
			print(ce)
		else:
			print(-1)
	t = t - 1


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	even = 0
	if n % 2 == 0:
		even = n // 2
	else:
		even = n // 2 + 1
	temp = 0
	incorrect = 0
	for i in range(len(a)):
		if a[i] % 2 == 0:
			temp += 1
			if i % 2 != 0:
				incorrect += 1
	if temp != even:
		print(-1)
		continue
	else:
		print(incorrect)


t = int(input())
for j in range(t):
	n = int(input())
	g = input().split()
	for i in range(n):
		g[i] = int(g[i])
	k1 = 0
	k2 = 0
	ch = 0
	nch = 0
	k = 0
	for i in range(n):
		if g[i] % 2 == 0:
			k1 += 1
		else:
			k2 += 1
	if n % 2 == 0:
		ch = n // 2
		nch = ch
	else:
		ch = n // 2 + 1
		nch = ch - 1
	if k1 == ch and k2 == nch:
		for i in range(n):
			if i % 2 != g[i] % 2:
				k += 1
		print(k // 2)
	else:
		print(-1)


def solve():
	n = int(input())
	arr = [int(v) for v in input().split()]
	wrong1s = 0
	wrong0s = 0
	moves = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if arr[i] % 2 == 0:
				wrong0s += 1
			else:
				wrong1s += 1
	if wrong1s != wrong0s:
		print(-1)
		return
	print(wrong1s)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	move = 0
	(ind, val) = ([], [])
	for i in range(n):
		if i % 2 != a[i] % 2:
			move += 1
		val.append(a[i] % 2)
		ind.append(i % 2)
	if val.count(1) == ind.count(1) or val.count(0) == ind.count(0):
		print(move // 2)
	else:
		print(-1)


import sys
input = sys.stdin.readline
testcases = int(input())

def invr():
	return map(int, input().split())
for _ in range(testcases):
	size = int(input())
	arr = invr()
	even = odd = 0
	for (ind, num) in enumerate(arr):
		if ind % 2 == 0 and num % 2 == 1:
			odd += 1
		elif ind % 2 == 1 and num % 2 == 0:
			even += 1
	if even != odd:
		print('-1')
	else:
		print(even)


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	ne = 0
	no = 0
	for i in range(n):
		if a[i] % 2 == 0:
			ne += 1
		else:
			no += 1
	if ne == no or ne - 1 == no:
		count = 0
		for i in range(n):
			if a[i] % 2 == 0 and i % 2 == 0 or (a[i] % 2 == 1 and i % 2 == 1):
				count += 1
		ans = int((n - count) / 2)
		print(ans)
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	list1 = list(map(int, input().split(' ')))
	even = odd = 0
	for (i1, j1) in enumerate(list1):
		if not i1 & 1:
			if i1 & 1 != j1 & 1:
				even += 1
		elif i1 & 1 != j1 & 1:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	if len(arr) == 1:
		if arr[0] % 2 == 0:
			print(0)
		else:
			print(-1)
	else:
		i = 0
		j = 1
		c1 = 0
		c2 = 0
		while i <= len(arr) - 1:
			if arr[i] % 2 != 0:
				c1 += 1
			i = i + 2
		while j <= len(arr) - 1:
			if arr[j] % 2 == 0:
				c2 += 1
			j += 2
		if c1 == c2:
			print(c1)
		if c1 > c2 or c2 > c1:
			print(-1)
	t -= 1


import sys
from collections import defaultdict as dd
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	q = int(input())
	w = list(map(int, input().split()))
	a = 0
	b = 0
	for i in range(q):
		if w[i] % 2 == 0 and i % 2 == 1:
			a += 1
		if w[i] % 2 == 1 and i % 2 == 0:
			b += 1
	if a == b:
		print(a)
	else:
		print(-1)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	lista = list(map(int, input().split()))
	contbadp = 0
	contbadi = 0
	for k in range(n):
		if k % 2 == 0 and lista[k] % 2 == 1:
			contbadp += 1
		elif k % 2 == 1 and lista[k] % 2 == 0:
			contbadi += 1
	if contbadp == contbadi:
		print(contbadp)
	else:
		print(-1)
test = int(input())
while test != 0:
	solve()
	test -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ch1 = []
	ch2 = []
	for i in range(n):
		ch1.append(i % 2)
		ch2.append(arr[i] % 2)
	(temp1, temp2) = (list(ch1), list(ch2))
	temp1.sort()
	temp2.sort()
	if temp1 == temp2:
		ans = 0
		for i in range(n):
			if ch1[i] != ch2[i]:
				ans += 1
		print(ans // 2)
	else:
		print(-1)


test_cases = int(input())

def is_good(ind, element):
	return ind % 2 == element % 2
for i in range(test_cases):
	size = int(input())
	arr = list(map(int, input().split()))
	(odds, evens) = (0, 0)
	for i in range(size):
		if not is_good(i, arr[i]):
			if i % 2 == 0:
				evens += 1
			else:
				odds += 1
	if odds == evens:
		print(odds)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	values = list(map(int, input().split()))
	odd_count = 0
	even_count = 0
	for i in range(n):
		if i % 2 == 0:
			if values[i] % 2 != 0:
				even_count += 1
		elif i % 2 != 0:
			if values[i] % 2 == 0:
				odd_count += 1
	if even_count == odd_count:
		print(even_count)
	else:
		print(-1)


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 == 0:
		c = n // 2
		nc = c
	else:
		c = n // 2 + 1
		nc = n - c
	(cc, ncc) = (0, 0)
	k = 0
	for i in range(n):
		if a[i] % 2 == 0:
			cc += 1
			if i % 2 == 1:
				k += 1
		else:
			ncc += 1
	if cc == c and ncc == nc:
		print(k)
	else:
		print(-1)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	e = o = 0
	for i in range(n):
		if a[i] & 1 and i & 1 == 0:
			o += 1
		elif a[i] & 1 == 0 and i & 1:
			e += 1
	print(e if e == o else -1)


t = int(input())
p = 1
while p <= t:
	n = int(input())
	arr = list((int(num) for num in input().strip().split()))[:n]
	i = 0
	x = 0
	y = 0
	while i < n:
		if i % 2 == 0 and arr[i] % 2:
			x += 1
		elif i % 2 and arr[i] % 2 == 0:
			y += 1
		i += 1
	if x == y:
		print(x)
	else:
		print('-1')
		print('\r')
	p += 1


t = int(input())
for x in range(t):
	n = int(input())
	num = list(map(int, input().split()))
	even = []
	for y in range(n):
		num[y] = num[y] % 2
	if num.count(1) != n // 2:
		print(-1)
	else:
		for z in range(n):
			if z % 2 == 0:
				even.append(num[z])
		print(even.count(1))


nn = int(input())
for _ in range(nn):
	n = int(input())
	arr = [int(i) for i in input().split()]
	no = 0
	ne = 0
	for i in range(len(arr)):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				no += 1
			else:
				ne += 1
	if no == ne:
		print(no)
	else:
		print(-1)


for l in range(int(input())):
	count = 0
	even = 0
	odd = 0
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 == 0:
				count += 1
			else:
				even += 1
		elif a[i] % 2 == 1:
			count += 1
		else:
			odd += 1
	if count == n:
		print('0')
	elif even == odd:
		print(even)
	else:
		print('-1')


n = int(input())
for i in range(n):
	m = int(input())
	a = list(map(int, input().split()))
	s1 = 0
	s2 = 0
	for j in range(len(a)):
		if j % 2 == 0 and a[j] % 2 == 1:
			s1 = s1 + 1
		elif j % 2 == 1 and a[j] % 2 == 0:
			s2 = s2 + 1
	if s1 != s2:
		print(-1)
	else:
		print(s1)


from itertools import permutations
from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
a = int(input())
for i in range(a):
	b = int(input())
	if b == 1:
		x = int(input())
		if x % 2 == 0:
			print('0')
		else:
			print('-1')
	elif b == 2:
		(y, z) = map(int, input().split())
		if y % 2 == 0 and z % 2 == 1:
			print('0')
		elif y % 2 == 1 and z % 2 == 0:
			print('1')
		else:
			print('-1')
	else:
		l = list(map(int, input().split()))
		(c, d) = ([], [])
		k = 0
		while k < len(l):
			m = k % 2
			n = l[k] % 2
			if m != n:
				c.append(l[k])
			k += 2
		s = 1
		while s < len(l):
			o = s % 2
			p = l[s] % 2
			if o != p:
				d.append(l[s])
			s += 2
		if len(c) == len(d):
			print(len(c))
		else:
			print('-1')


from collections import defaultdict, Counter
import copy, math
from copy import deepcopy
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 != 0:
			e += 1
		if i % 2 != 0 and l[i] % 2 == 0:
			o += 1
	if e != o:
		print(-1)
	else:
		print(e)


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	i = 0
	j = 1
	odd = 0
	eve = 0
	if n == 1:
		if arr[0] % 2:
			print('-1')
			continue
		else:
			print('0')
			continue
	while i < n:
		if arr[i] % 2:
			odd += 1
		i += 2
	while j < n:
		if arr[j] % 2 == 0:
			eve += 1
		j += 2
	if odd == eve:
		print(odd)
		continue
	else:
		print('-1')
		continue


def problem():
	input()
	nums = [int(i) % 2 for i in input().split()]
	(inc_ones, inc_zeros) = (0, 0)
	for (ind, num) in enumerate(nums):
		if ind % 2 != num:
			if num == 1:
				inc_ones += 1
			else:
				inc_zeros += 1
	if inc_ones == inc_zeros:
		print(inc_ones)
	else:
		print(-1)
for i in range(int(input())):
	problem()
	print()


import math
a = int(input())
for i in range(a):
	n = int(input())
	b = [int(x) for x in input().split()]
	odd = 0
	even = 0
	wrongplace = 0
	for j in range(n):
		if b[j] % 2 == 0:
			even += 1
			if j % 2 != 0:
				wrongplace += 1
		else:
			odd += 1
			if j % 2 == 0:
				wrongplace += 1
	if math.ceil(n / 2) == even and n // 2 == odd:
		print(int(wrongplace / 2))
	else:
		print(-1)


t = int(input())
for test in range(t):
	n = int(input())
	a = input()
	a = a.strip()
	a = a.split(' ')
	a = list(map(int, a))
	idx = []
	itm = []
	zero = 0
	one = 0
	count = 0
	for i in range(n):
		x = i % 2
		y = a[i] % 2
		idx.append(x)
		itm.append(y)
		if a[i] % 2 == 0:
			zero += 1
		elif a[i] % 2 == 1:
			one += 1
		if x != y:
			count += 1
	if len(itm) % 2 == 0:
		if zero != one:
			print(-1)
		else:
			print(int(count / 2))
	elif len(itm) % 2 == 1:
		if zero != one + 1:
			print(-1)
		else:
			print(int(count / 2))


n = int(input())
for i in range(0, n):
	x = int(input())
	a = list(map(int, input().split()))
	v = 0
	p = 0
	for i in range(0, len(a)):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				v = v + 1
		if i % 2 == 1:
			if a[i] % 2 == 0:
				p = p + 1
	if v == p:
		print(v)
	else:
		print(-1)


t = int(input())
for _ in range(0, t):
	n = int(input())
	arr = list(map(int, input().strip().split(' ')))
	good = 0
	bad = 0
	even = 0
	odd = 0
	for i in range(0, n):
		if i % 2 != arr[i] % 2:
			bad += 1
			if arr[i] % 2 == 0:
				even += 1
			else:
				odd += 1
		else:
			good += 1
	if bad % 2 == 0 and even == odd:
		print(bad // 2)
	else:
		print(-1)


t = int(input())
for tt in range(t):
	n = int(input())
	be = 0
	bo = 0
	ll = [int(x) for x in input().split()]
	for i in range(n):
		if i % 2 == 0 and ll[i] % 2 == 1:
			bo += 1
		elif i % 2 == 1 and ll[i] % 2 == 0:
			be += 1
	if be == bo:
		print(be)
	else:
		print(-1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	count_even = 0
	count_odd = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			count_even += 1 * (i % 2 == 0)
			count_odd += 1 * (i % 2 == 1)
	if count_odd == count_even:
		print(count_even)
	else:
		print(-1)


t = int(input())
for case in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	good_even = 0
	bad_even = 0
	good_odd = 0
	bad_odd = 0
	for i in range(len(arr)):
		if (i - arr[i]) % 2 == 0:
			if arr[i] % 2 == 0:
				good_even += 1
			else:
				good_odd += 1
		elif arr[i] % 2 == 0:
			bad_even += 1
		else:
			bad_odd += 1
	if bad_even != bad_odd:
		print(-1)
	else:
		print(bad_even)


import sys
import math
sys.setrecursionlimit(1000000)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')
p2S = lambda x: print(*x, sep=' ')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	_v_ = II()
	for ___ in range(_v_):
		n = II()
		s = LI()
		fj = 0
		fe = 0
		for i in range(len(s)):
			if i & 1 == 1 and s[i] & 1 == 0:
				fj += 1
			elif i & 1 == 0 and s[i] & 1 == 1:
				fe += 1
		if fj != fe:
			print(-1)
		else:
			print(fj + fe >> 1)
main()


t = int(input())
res = []
for i in range(t):
	n = int(input())
	arr = [x % 2 for x in map(int, input().split())]
	a = 0
	b = 0
	for j in range(n):
		if arr[j] != j % 2 and j % 2 == 1:
			a += 1
		elif arr[j] != j % 2 and j % 2 == 0:
			b += 1
	if a == b:
		res.append(b)
	else:
		res.append(-1)
print('\n'.join([str(x) for x in res]))


for _ in range(int(input())):
	m = int(input())
	arr = list(map(int, input().split()))
	n = []
	for k in range(m):
		if k % 2 == 0:
			if arr[k] % 2 == 0:
				n.append(0)
			else:
				n.append('e')
		elif arr[k] % 2 != 0:
			n.append(0)
		else:
			n.append('o')
	p = n.count('e')
	q = n.count('o')
	if p != q:
		print(-1)
	else:
		print(p)


a = input()
for x in range(int(a)):
	c = input()
	b = input().split(' ')
	ans = 0
	tag = 0
	tag1 = 0
	for i in range(len(b)):
		if int(b[i]) % 2 == 0:
			tag += 1
			if i % 2 != 0:
				ans += 1
		else:
			tag1 += 1
			if i % 2 != 1:
				ans += 1
	if ans % 2 == 0 and tag == (int(c) + 1) // 2 and (tag1 == int(c) // 2):
		print(ans // 2)
	else:
		print(-1)


for y in range(int(input())):
	m = int(input())
	b = list(map(int, input().split()))
	c = []
	for x in range(m):
		if x % 2 == 0:
			if b[x] % 2 == 0:
				c.append(0)
			else:
				c.append('i')
		elif b[x] % 2 != 0:
			c.append(0)
		else:
			c.append('j')
	k1 = c.count('i')
	k2 = c.count('j')
	if k1 != k2:
		print('-1')
	else:
		print(k1)


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for case in range(0, t):
	n = inp()
	l = inlt()
	a = 0
	b = 0
	for i in range(0, n):
		if i % 2 == 0 and l[i] % 2 != 0:
			a += 1
		if i % 2 != 0 and l[i] % 2 == 0:
			b += 1
	if a != b:
		print(-1)
	else:
		print(a)


t = int(input())
for time in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	for i in range(n):
		if i % 2 != a[i] % 2 and a[i] % 2 == 1:
			c1 += 1
		elif i % 2 != a[i] % 2 and a[i] % 2 == 0:
			c2 += 1
	print(c1 if c1 == c2 else -1)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	iseven = [i % 2 for i in a[::2]].count(1)
	isodd = [i % 2 for i in a[1::2]].count(0)
	if iseven == isodd:
		print(iseven)
	else:
		print(-1)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def solve():
	n = int(inp())
	ar = lis()
	co = 0
	ce = 0
	for i in range(n):
		if i % 2 == 0 and ar[i] % 2 == 1:
			ce += 1
		if i % 2 == 1 and ar[i] % 2 == 0:
			co += 1
	if ce != co:
		print(-1)
	else:
		print(co)
testcase(int(inp()))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	oddDk = evenDk = 0
	for i in range(n):
		if i % 2 != l[i] % 2 and i % 2 == 1:
			oddDk += 1
		elif i % 2 != l[i] % 2 and i % 2 == 0:
			evenDk += 1
	if evenDk == oddDk:
		print(evenDk)
	else:
		print(-1)


from math import *
from copy import *
from heapq import *
from string import *
from random import *
from bisect import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from decimal import Decimal
from collections import Counter
from collections import defaultdict

def solve(l):
	n = len(l)
	c = 0
	(e, o) = (0, 0)
	for i in range(n):
		if i & 1 != l[i] & 1:
			c += 1
		if l[i] & 1:
			o += 1
		else:
			e += 1
	if n & 1:
		if o > n // 2:
			return -1
		if e > ceil(n / 2):
			return -1
	elif o > n // 2 or e > n // 2:
		return -1
	return c // 2
T = int(input())
for _ in range(T):
	N = int(stdin.readline())
	l = list(map(int, stdin.readline().rstrip().split()))
	print(solve(l))


t = int(input())
for w in range(t):
	n = int(input())
	x = [int(i) for i in input().split()]
	v = [-1 for i in range(n)]
	for i in range(n):
		if i % 2 != x[i] % 2:
			v[i] = x[i] % 2
	a = v.count(0)
	b = v.count(1)
	if a == b:
		print(a)
	else:
		print(-1)


from sys import stdin, stdout
import sys
INF = 1000000000.0
import bisect

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
import math
for _ in range(int(stdin.readline())):
	n = get_int()
	a = get_array()
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				odd += 1
		elif a[i] % 2 == 0:
			even += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


for x in range(int(input())):
	l = int(input())
	a = list(map(int, input().split()))
	(c1, c2) = (0, 0)
	i = 0
	while i < l:
		if i % 2 == 0 and a[i] % 2 == 1:
			c1 += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			c2 += 1
		i += 1
	if c1 != c2:
		print('-1')
	else:
		print(c1)


from sys import stdin, stdout
read = stdin.readline

def puts(x, end='\n'):
	stdout.write(x + end)

def read_int():
	return int(read())

def list_in():
	return [i for i in read().split()]

def int_list_in():
	return [int(i) for i in read().split()]

def solve():
	read()
	array = int_list_in()
	odd = 0
	even = 0
	for (index, val) in enumerate(array):
		if index % 2 != val % 2:
			if index % 2 == 0:
				even += 1
			else:
				odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)
for i in range(read_int()):
	solve()


def solve(s, n):
	odd = 0
	even = 0
	elem = n
	for i in range(0, n):
		if s[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if i % 2 == s[i] % 2:
			elem -= 1
	if n % 2 == 0 and even != odd or (n % 2 == 1 and even != odd + 1):
		return -1
	else:
		return elem // 2
t = int(input())
for i in range(0, t):
	n = int(input())
	s = list(map(int, input().split()))
	print(solve(s, n))


tests = int(input())
for _ in range(tests):
	n = int(input())
	sp = list(map(int, input().split()))
	ch = 0
	for i in sp:
		if i % 2 == 0:
			ch += 1
	if ch != n - n // 2:
		print(-1)
		continue
	count = 0
	for i in range(n):
		if i % 2 != sp[i] % 2:
			count += 1
	print(count // 2)


for _ in range(int(input())):
	size = int(input())
	arr = list(map(int, input().split()))
	correct = 0
	zeros = 0
	for i in range(size):
		if arr[i] % 2 == 0:
			zeros += 1
		if arr[i] % 2 == 0 and i % 2 == 0 or (arr[i] % 2 == 1 and i % 2 == 1):
			correct += 1
	if size % 2 != 0 and zeros != (size + 1) // 2 or (size % 2 == 0 and zeros != size // 2):
		print(-1)
	else:
		print((size - correct) // 2)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	e = 0
	o = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			e += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			o += 1
	if o == e:
		print(o)
	else:
		print(-1)


import sys
import math
import operator as op
from functools import reduce
from bisect import *
from collections import deque

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom

def index(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return -1

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return i - 1
	return -1

def find_le(a, x):
	i = bisect_right(a, x)
	if i:
		return i - 1
	return -1

def find_gt(a, x):
	i = bisect_right(a, x)
	if i != len(a):
		return i
	return -1

def find_ge(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return i
	return -1
mod = int(1000000000.0) + 7
mod2 = 998244353
t = read_int()
for i in range(t):
	n = read_int()
	a = read_int_line()
	cnt = [0] * n
	for i in range(n):
		if i & 1 == 0 and a[i] & 1 == 1:
			cnt[i] = 1
		elif i & 1 == 1 and a[i] & 1 == 0:
			cnt[i] = -1
	if sum(cnt) == 0:
		print(cnt.count(1))
	else:
		print(-1)


test = int(input())
for _ in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(n):
		if not i % 2:
			if a[i] % 2:
				e += 1
		elif not a[i] % 2:
			o += 1
	if e == o:
		print(e)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	n_e = [0, 0]
	for (i, e) in enumerate(a):
		if i % 2 != e % 2:
			n_e[i % 2] += 1
	if n_e[0] == n_e[1]:
		print(n_e[0])
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	odd_count = 0
	even_count = 0
	odd_a = n // 2
	even_a = n - odd_a
	switch_c = 0
	for j in range(n):
		if a[j] % 2 == 0:
			even_count = even_count + 1
		else:
			odd_count = odd_count + 1
	if even_count != even_a:
		print(-1)
	else:
		for k in range(n):
			if k % 2 == 0 and a[k] % 2 == 0 or (k % 2 != 0 and a[k] % 2 != 0):
				continue
			else:
				for z in range(k + 1, n):
					if z % 2 == 0 and a[z] % 2 == 0 or (z % 2 != 0 and a[z] % 2 != 0) or (k % 2 == 0 and a[z] % 2 != 0) or (k % 2 != 0 and a[z] % 2 == 0):
						continue
					else:
						switch_c = switch_c + 1
						temp = a[z]
						a[z] = a[k]
						a[k] = temp
						break
		print(switch_c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	e = 0
	o = 0
	f = True
	for i in range(len(a)):
		if i & 1:
			if a[i] & 1 == 0:
				o += 1
		elif a[i] & 1:
			e += 1
	if e == o:
		print(e)
	else:
		print('-1')


from sys import stdin, stdout
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()
import math
from collections import Counter

def solve():
	n = IN()
	a = LI()
	f = 0
	e = 0
	for i in range(n):
		if a[i] % 2 == 0:
			e += 1
		if i % 2 != a[i] % 2:
			f += 1
	if (n + 1) // 2 != e:
		print(-1)
	else:
		print(f // 2)
for i in range(IN()):
	solve()


t = int(input())
for i in range(t):
	s = int(input())
	D = list(map(int, input().split()))
	x = 0
	y = 0
	for j in range(len(D)):
		if D[j] % 2 != j % 2:
			if j % 2 == 0:
				x += 1
			else:
				y += 1
	if x != y:
		print(-1)
	else:
		print(x)


t = int(input())
while t != 0:
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	count1 = 0
	for i in range(0, n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			count += 1
		if i % 2 == 1 and arr[i] % 2 != 1:
			count1 += 1
	if count == count1:
		print(int(count))
	else:
		print('-1')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	ind = []
	nos = []
	i_even = 0
	i_odd = 0
	nos_even = 0
	nos_odd = 0
	for i in range(n):
		if i % 2 == 0:
			i_even += 1
		else:
			i_odd += 1
		ind.append(i % 2)
		if nums[i] % 2 == 0:
			nos_even += 1
		else:
			nos_odd += 1
		nos.append(nums[i] % 2)
	if i_even != nos_even or i_odd != nos_odd:
		print(-1)
		continue
	mis_even = 0
	mis_odd = 0
	for i in range(n):
		if ind[i] != nos[i]:
			if i % 2 == 0:
				mis_even += 1
			else:
				mis_odd += 1
	if mis_even != mis_odd:
		print(-1)
		continue
	print(mis_even)


t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	o = []
	e = []
	for i in range(n):
		if i % 2 is 0 and l[i] % 2 is 0:
			pass
		elif i % 2 != 0 and l[i] % 2 != 0:
			pass
		elif i % 2 is 0 and l[i] % 2 != 0:
			e.append(i)
		else:
			o.append(i)
	if len(o) != len(e):
		print(-1)
	else:
		print(len(o))
	t -= 1


import sys

def calculate(numbers):
	invalidOddIdxCount = 0
	invalidEvenIdxCount = 0
	for (idx, rawNumber) in enumerate(numbers):
		number = int(rawNumber)
		if number % 2 == 0:
			if idx % 2 != 0:
				invalidEvenIdxCount += 1
		elif idx % 2 != 1:
			invalidOddIdxCount += 1
	if invalidEvenIdxCount == invalidOddIdxCount:
		return int((invalidEvenIdxCount + invalidOddIdxCount) / 2)
	else:
		return -1
inputs = []
numOfInput = sys.stdin.readline()
for inputIndex in range(0, int(numOfInput)):
	sys.stdin.readline()
	inputs.append(sys.stdin.readline().split(' '))
for lineInput in inputs:
	result = calculate(lineInput)
	sys.stdout.write(str(result) + '\n')
	sys.stdout.flush()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = [int(x) for x in input().split()]
	oie = 0
	eio = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			if i % 2 == 1:
				eio += 1
			else:
				oie += 1
	if eio != oie:
		print(-1)
	else:
		print(oie)


for tt in range(int(input())):
	c1 = 0
	c2 = 0
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1 and arr[0] % 2 != 0:
		print('-1')
	else:
		for i in range(n):
			if i % 2 == 0 and arr[i] % 2 != 0:
				c1 += 1
			elif i % 2 != 0 and arr[i] % 2 == 0:
				c2 += 1
			else:
				continue
		if c1 == c2:
			print(c1)
		else:
			print('-1')


s = int(input())
count = 0
ans = []
while count < s:
	n = int(input())
	a = input()
	a = [int(x) for x in a.split()]
	if n % 2 == 0:
		no_even = n // 2
	else:
		no_even = n // 2 + 1
	test1 = [int(x) for x in a if x % 2 == 0]
	if len(test1) == no_even:
		change = 0
		even = a[0::2]
		for x in even:
			if x % 2 != 0:
				change += 1
		ans.append(change)
	else:
		ans.append(-1)
	count += 1
for y in ans:
	print(y)


def solve(a, n):
	(c1, c2) = (0, 0)
	for i in range(n):
		a2 = a[i] % 2
		i2 = i % 2
		if a2 != i2:
			if a2 == 0:
				c2 += 1
			else:
				c1 += 1
	if c1 == c2:
		return c1
	else:
		return -1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(a, n))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	onp = 0
	enp = 0
	for i in range(n):
		if i & 1 != a[i] & 1:
			if a[i] & 1:
				onp += 1
			else:
				enp += 1
	if onp == enp:
		print(onp)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	co = 0
	ce = 0
	cdiff = 0
	for x in range(n):
		if a[x] % 2 == 0:
			ce = ce + 1
		if a[x] % 2 != 0:
			co = co + 1
		if a[x] % 2 != 0 and x % 2 == 0:
			cdiff = cdiff + 1
		if a[x] % 2 == 0 and x % 2 != 0:
			cdiff = cdiff + 1
	if n % 2 == 0 and ce != co:
		print(-1)
	elif n % 2 != 0 and n // 2 != co:
		print(-1)
	else:
		print(cdiff // 2)


import sys, math, cmath, time
start_time = time.time()

def solve():
	n = inp()
	a = inlt()
	q = 0
	w = 0
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				q = q + 1
			else:
				w = w + 1
	if q != w:
		q = -1
	print(q)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


def result(lst):
	amount = 0
	for k in range(n):
		if k % 2 != lst[k] % 2:
			for g in range(k + 1, n):
				if k % 2 == lst[g] % 2 and g % 2 != lst[g] % 2:
					(lst[k], lst[g]) = (lst[g], lst[k])
					amount += 1
					break
	print(amount)
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	odds = 0
	evens = 0
	for j in a:
		if j % 2 == 0:
			evens += 1
		else:
			odds += 1
	if n % 2 == 0:
		if evens != odds:
			print(-1)
		else:
			result(a)
	elif evens - odds != 1:
		print(-1)
	else:
		result(a)


def solve(n, a):
	even = odd = 0
	for (i, x) in enumerate(a):
		if i % 2 == 0:
			even += int(x % 2 != 0)
		else:
			odd += int(x % 2 == 0)
	return even if even == odd else -1
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


from sys import stdin
N = int(stdin.readline())
for case in range(N):
	length = int(stdin.readline())
	array = list(map(int, stdin.readline().split()))
	i = 0
	parities = [0, 0]
	parity = 0
	while i < length:
		if array[i] % 2 != parity:
			parities[parity] += 1
		i += 1
		parity = [1, 0][parity]
	if parities[0] == parities[1]:
		print(parities[0])
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = []
	for i in range(n):
		x.append(i % 2)
	c = 0
	e = 0
	o = 0
	for i in range(n):
		if l[i] % 2 != x[i]:
			c = c + 1
			if l[i] % 2 == 0:
				e = e + 1
			else:
				o = o + 1
	if c % 2 == 0 and e == o:
		print(c // 2)
	else:
		print(-1)


from math import ceil, floor
t = int(input())
for i in range(t):
	n = int(input())
	l = [int(i) % 2 for i in input().split()]
	nech = l.count(1)
	nech_l = floor(n / 2)
	if nech == nech_l:
		(chet_c, nech_c) = (0, 0)
		for i in range(len(l)):
			if i % 2 != l[i]:
				if l[i] == 0:
					chet_c += 1
				else:
					nech_c += 1
		if chet_c == nech_c:
			print(chet_c)
		else:
			print(-1)
	else:
		print(-1)


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
import io, os
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().strip().split()))
rls = lambda : list(map(str, input().split()))
t = int(input())
for _ in range(0, t):
	n = int(input())
	a = rl()
	e = 0
	o = 0
	for i in range(0, n):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				e = e + 1
			else:
				o = o + 1
	if o == e:
		print(o)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	flag = 0
	o = 0
	e = 0
	for i in l:
		if flag == 0:
			if i % 2 != 0:
				e = e + 1
			flag = 1
			continue
		if flag == 1:
			if i % 2 != 1:
				o = o + 1
			flag = 0
			continue
	if e == o:
		print(e)
	else:
		print('-1')


from sys import stdin

def input():
	return stdin.readline()
for _ in range(int(input())):
	n = int(input())
	arr = list(map(lambda x: int(x) % 2, input().split()))
	w = 0
	if n % 2 == 0:
		if arr.count(0) == n // 2:
			for i in range(n):
				if i % 2 != arr[i]:
					w += 1
			print(w // 2)
		else:
			print(-1)
	elif arr.count(0) == (n + 1) // 2:
		for i in range(n):
			if i % 2 != arr[i]:
				w += 1
		print(w // 2)
	else:
		print(-1)


T = int(input())
for t in range(1, T + 1):
	N = int(input())
	lst = input().split()
	for i in range(N):
		lst[i] = int(lst[i])
	odd = 0
	even = 0
	for i in range(N):
		if i % 2 == 0 and lst[i] % 2 == 1:
			even += 1
		elif i % 2 == 1 and lst[i] % 2 == 0:
			odd += 1
	if even == odd:
		print(odd)
	else:
		print(-1)


z = int(input())
for _ in range(z):
	a = int(input())
	arr = list(map(int, input().split()))
	l = [0, 0]
	for i in range(a):
		if arr[i] % 2 != i % 2:
			l[i % 2] += 1
	if l[0] == l[1]:
		print(l[0])
	else:
		print(-1)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	(even, odd, ans, i) = (0, 0, 0, 0)
	while i < n:
		if l[i] % 2 == 1:
			odd += 1
			if i % 2 == 0:
				ans += 1
		else:
			even += 1
		i += 1
	if odd != math.floor(n / 2):
		print('-1')
	else:
		print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [j % 2 for j in range(n)]
	c = [a[j] % 2 for j in range(n)]
	(d, e) = ([], [])
	for j in range(n):
		if c[j] != b[j] and c[j] == 0:
			d.append(j)
		elif c[j] != b[j] and c[j] == 1:
			e.append(j)
	if len(d) == len(e):
		print(len(d))
	else:
		print(-1)


import sys
import random
from math import *

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

def rlinput():
	return list(map(int, input().split()))

def trinput():
	return tuple(rinput())

def srlinput():
	return sorted(list(map(int, input().split())))

def YESNO(fl):
	if fl:
		print('NO')
	else:
		print('YES')

def main():
	n = iinput()
	q = rlinput()
	t = 0
	for i in range(n):
		q[i] %= 2
		if q[i] != i % 2:
			t += 1
	if sum(q) != n // 2:
		print(-1)
	else:
		print(t // 2)
for inytd in range(iinput()):
	main()


def sample(a, n):
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				even += 1
		if i % 2 != 0:
			if a[i] % 2 == 0:
				odd += 1
	if even == odd:
		return even
	else:
		return -1
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(sample(a, n))


t = int(input())
answer = []
for a in range(t):
	counterodd = 0
	countereven = 0
	n = int(input())
	line = [int(i) for i in input().split()]
	for j in range(n):
		if j % 2 == 1 and line[j] % 2 == 0:
			counterodd += 1
		elif j % 2 == 0 and line[j] % 2 == 1:
			countereven += 1
	if countereven != counterodd:
		answer.append(-1)
	else:
		answer.append(counterodd)
for b in answer:
	print(str(b))


def isValid(arr):
	(f, flag2, ms) = (0, True, 0)
	for i in arr:
		if f != i:
			flag2 = False
			ms += 1
		f = (f + 1) % 2
	return (flag2, ms)

def getZ1(arr):
	l12 = len(arr) // 2
	if len(arr) % 2 == 0:
		return (l12, l12)
	return (l12, l12 + 1)

def isPossible(arr):
	(n1, n2) = (arr.count(1), arr.count(0))
	(nf1, nf2) = getZ1(arr)
	if nf1 == n1 and nf2 == n2:
		return True
	return False

def processList(arr):
	for i in range(len(arr)):
		arr[i] = arr[i] % 2
	return arr

def getInput():
	return (int(input()), processList(list(map(int, input().split()))))

def getWays(arr):
	(flag, ms) = isValid(arr)
	if flag:
		return 0
	if not isPossible(arr):
		return -1
	return ms // 2

def rmain():
	t = int(input())
	for i in range(t):
		(l1, li) = getInput()
		print(getWays(li))
	return
rmain()


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				count1 += 1
		elif l[i] % 2 != 1:
			count2 += 1
	if count1 == count2:
		if count1 == 0:
			print(count1)
		else:
			print(count1)
	else:
		print(-1)


def solve():
	size = int(input())
	arr = list(map(int, input().split()))
	count1 = 0
	count0 = 0
	for i in range(0, size):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				count0 += 1
			else:
				count1 += 1
	if (count0 + count1) % 2 == 0 and count0 == count1:
		print((count0 + count1) // 2)
	else:
		print(-1)
tc = int(input())
for i in range(tc):
	solve()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	w = 0
	v = 0
	for i in range(n):
		if i % 2 < arr[i] % 2:
			w += 1
		elif i % 2 > arr[i] % 2:
			v += 1
	if w == v:
		print(w)
	else:
		print(-1)


for _ in range(int(input())):
	input()
	a = list(map(int, input().split()))
	ss1 = sum((1 for (i, n) in enumerate(a) if i % 2 != n % 2 and n % 2))
	ss2 = sum((1 for (i, n) in enumerate(a) if i % 2 != n % 2 and n % 2 == 0))
	print(ss1 if ss1 == ss2 else -1)


T = int(input())
for _ in range(1, T + 1):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr_bool = [False for x in arr]
	for i in range(n):
		if arr[i] % 2 == i % 2:
			arr_bool[i] = True
	cnt = 0
	cnt_odd = 0
	cnt_even = 0
	for i in range(n):
		if not arr_bool[i]:
			cnt += 1
			if i % 2 == 0:
				cnt_odd += 1
			else:
				cnt_even += 1
	cnt = arr_bool.count(False)
	if cnt % 2 == 1 or cnt_even != cnt_odd:
		print(-1)
	elif cnt == 0:
		print(0)
	else:
		print(cnt // 2)


import sys
input = sys.stdin.readline

def solve(n, arr):
	parity_count = {0: 0, 1: 0}
	for (i, v) in enumerate(arr):
		if i % 2 == v % 2:
			continue
		else:
			parity_count[v % 2] += 1
	if parity_count[0] == parity_count[1]:
		return parity_count[0]
	else:
		return -1
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(n, arr))


import sys, os.path, math
pwd = os.path.dirname(__file__)
if os.path.exists(os.path.join(pwd, '../iostream/input.txt')):
	sys.stdin = open(os.path.join(pwd, '../iostream/input.txt'), 'r')
	sys.stdout = open(os.path.join(pwd, '../iostream/output.txt'), 'w')

def solve():
	for i in range(int(input())):
		length = int(input())
		array = [int(j) for j in input().split()]
		odd = []
		even = []
		for j in range(length):
			if j & 1 != array[j] & 1:
				if array[j] & 1:
					odd.append(array[j])
				else:
					even.append(array[j])
		if len(odd) == len(even):
			print(len(odd))
		else:
			print(-1)
solve()


cases_number = int(input())
answers = [0 for i in range(cases_number)]
for i in range(cases_number):
	length = int(input())
	arr = [int(j) for j in input().split()]
	arr_1 = [(arr[k] - k) % 2 * (-1) ** k for k in range(length)]
	if sum(arr_1) != 0:
		answers[i] = -1
	else:
		arr_2 = [abs(k) for k in arr_1]
		answers[i] = sum(arr_2) // 2
for answer in answers:
	print(answer)


t = int(input())

def decode(a):
	wrong_evens = 0
	wrong_adds = 0
	for (i, _) in enumerate(a):
		if i % 2 != a[i] % 2:
			if i % 2:
				wrong_adds += 1
			else:
				wrong_evens += 1
	if wrong_evens != wrong_adds:
		return -1
	else:
		return wrong_adds
for line in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(decode(a))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	for i in range(n):
		if i % 2 != l[i] % 2:
			l1.append([i % 2, l[i] % 2])
	if len(l1) == 0:
		print(0)
	else:
		count = 0
		j = 0
		k = j + 1
		p = len(l1)
		while j < len(l1):
			while k < len(l1):
				if l1[j][0] == l1[k][1] and l1[j][1] == l1[k][0] and (l1[j] != l1[k]):
					count += 1
					del l1[j]
					del l1[k - 1]
					j -= 1
					k -= 1
					break
				k += 1
			j += 1
		if len(l1) != 0:
			print(-1)
		else:
			print(count)


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for i in range(1):
		num = list(map(int, input().split()))
		l += num
	(ctre, ctro) = (0, 0)
	for i in range(len(l)):
		if i % 2 == 0 and l[i] % 2 != 0:
			ctre += 1
		elif i % 2 != 0 and l[i] % 2 == 0:
			ctro += 1
	if ctre != ctro:
		print(-1)
	else:
		print(ctre)


for j in range(int(input())):
	s = int(input())
	l = list(map(int, input().split()))
	a = 0
	c = 0
	for i in range(s):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				a += 1
			else:
				continue
		if i % 2 != 0:
			if l[i] % 2 == 0:
				c += 1
			else:
				continue
	if a == c:
		print(a)
	else:
		print(-1)


t = int(input(''))
for i in range(t):
	n = int(input(''))
	a = list(map(int, input('').split()))
	odd = 0
	even = 0
	for k in range(n):
		if a[k] % 2 == 1 and k % 2 == 0:
			odd += 1
		elif a[k] % 2 == 0 and k % 2 == 1:
			even += 1
	if even != odd:
		print(-1)
	else:
		ans = (odd + even) // 2
		print(ans)


try:
	for _ in range(int(input())):
		n = int(input())
		arr = [int(i) for i in input().split()]
		(even, odd) = (0, 0)
		for i in range(0, n, 2):
			if arr[i] % 2 != 0:
				even += 1
		for i in range(1, n, 2):
			if arr[i] % 2 != 1:
				odd += 1
		if even != odd:
			print(-1)
		else:
			print(even)
except:
	pass


t = int(input())
for _ in range(t):
	n = int(input())
	lis1 = list(map(int, input().split()))
	(ec, oc) = (0, 0)
	for i in range(len(lis1)):
		if i % 2 == 0 and lis1[i] % 2 != 0:
			ec += 1
		if i % 2 == 1 and lis1[i] % 2 != 1:
			oc += 1
	if oc == ec:
		print(ec)
	else:
		print(-1)


def mod(l, n):
	(e, o) = (0, 0)
	y = 0
	for i in l:
		if y == 0:
			if i % 2 == 1:
				e += 1
			y = 1
		elif y == 1:
			if i % 2 == 0:
				o += 1
			y = 0
	if e != o:
		return -1
	return e
for _ in range(int(input())):
	n = int(input())
	parity = list(map(int, input().split()))
	print(mod(parity, n))


def solve(a):
	bad = [0, 0]
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			bad[i % 2] += 1
	if bad[0] != bad[1]:
		print(-1)
	else:
		print(bad[0])
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	solve(a)


def solve(n, s):
	e_count = 0
	o_count = 0
	par = []
	for i in s:
		m = i % 2
		if m == 0:
			e_count += 1
		else:
			o_count += 1
		par.append(m)
	if n % 2 == 0:
		if e_count != o_count:
			return -1
	elif o_count + 1 != e_count:
		return -1
	c = 0
	for i in range(n):
		if i % 2 != par[i]:
			c += 1
	return c // 2
t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	print(solve(n, s))


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	(em, om) = (0, 0)
	for (i, a) in enumerate(arr):
		if i % 2 == 0:
			if a % 2 != 0:
				em += 1
		elif a % 2 != 1:
			om += 1
	if em == om:
		print(em)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	e = []
	o = []
	for i in range(n):
		if i % 2 == 0:
			e.append(a[i])
		else:
			o.append(a[i])
	p = 0
	for i in e:
		if i % 2 != 0:
			p += 1
	q = 0
	for i in o:
		if i % 2 == 0:
			q += 1
	if p == q:
		print(p)
	else:
		print(-1)


n = int(input())
for i in range(n):
	l = int(input())
	arr = input().split()
	i = 0
	ceven = 0
	codd = 0
	for x in arr:
		if int(x) % 2 == 0 and i == 1:
			ceven += 1
		elif int(x) % 2 == 1 and i == 0:
			codd += 1
		if i == 0:
			i = 1
		else:
			i = 0
	if codd == ceven:
		print(codd)
	else:
		print(-1)


for _ in range(int(input())):
	_ = input()
	a = [int(x) for x in input().split()]
	(e, o) = (0, 0)
	ans = 0
	for (i, v) in enumerate(a):
		if i % 2 != v % 2:
			if i % 2 == 1:
				o += 1
			else:
				e += 1
			if e != 0 and o != 0:
				e -= 1
				o -= 1
				ans += 1
	if e != o:
		print(-1)
	else:
		print(ans)


def answer():
	n = int(input())
	while n:
		s = int(input())
		a = [int(x) for x in input().split()]
		i = 0
		bad = 0
		odds = 0
		evens = 0
		while i < len(a):
			if i % 2:
				if not a[i] % 2:
					bad += 1
			elif a[i] % 2:
				bad += 1
			if a[i] % 2:
				odds += 1
			else:
				evens += 1
			i += 1
		passed = 0
		if s % 2:
			if odds == evens - 1:
				passed = 1
		elif odds == evens:
			passed = 1
		if bad % 2 or not passed:
			print(-1)
		else:
			print(int(bad / 2))
		n -= 1
answer()


for i in range(int(input())):
	n = int(input())
	ans = 0
	arr = [int(i) for i in input().split()]
	o = []
	e = []
	for i in range(len(arr)):
		if arr[i] % 2 == 1:
			if i % 2 == 0:
				e.append(i)
		elif arr[i] % 2 == 0:
			if i % 2 == 1:
				o.append(i)
	if len(o) != len(e):
		ans = -1
	else:
		ans = len(o)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	even = sum([1 for x in a if x % 2 == 0])
	odd = sum([1 for x in a if x % 2 == 1])
	if even == odd or even - odd == 1:
		wrong_counter = sum([1 for x in range(n) if x & 1 != a[x] & 1])
		print(wrong_counter // 2)
	else:
		print(-1)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = int(input())
	a = list([int(s) % 2 for s in input().split()])
	if a.count(1) != n // 2:
		print(-1)
		return
	print(a[1::2].count(0))
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in range(n):
		if i % 2 == a[i] % 2:
			a[i] = True
		else:
			b.append(a[i] % 2)
			a[i] = False
	count = a.count(False)
	if count % 2 == 1:
		print(-1)
	elif b.count(1) == b.count(0):
		print(count // 2)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	h = nh = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 0:
				h += 1
			else:
				nh += 1
	if nh == h:
		print(nh)
	else:
		print(-1)


t = int(input())
for i1 in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	list1 = []
	even = 0
	odd = 0
	for i in range(n):
		if a[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	if n % 2 == 0 and even == odd or (n % 2 != 0 and even == odd + 1):
		for i in range(n):
			if (i + a[i]) % 2 != 0:
				list1.append(a[i])
		if len(list1) % 2 == 0:
			print(len(list1) // 2)
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	(l, s) = ([], [])
	c = 0
	for (i, j) in enumerate(lst):
		l.append(i % 2)
		s.append(j % 2)
	if l == s:
		print(0)
	elif sorted(l) != sorted(s):
		print(-1)
	else:
		for k in range(n):
			if l[k] != s[k]:
				c = c + 1
		print(c // 2)


def nmoves(a):
	cnt = 0
	neven = 0
	nodd = 0
	for (i, elem) in enumerate(a):
		if i % 2 != elem % 2:
			cnt += 1
		if elem % 2 == 0:
			neven += 1
		else:
			nodd += 1
	if len(a) % 2 != 0 and neven - nodd != 1 or (len(a) % 2 == 0 and neven != nodd):
		return -1
	else:
		return cnt // 2
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(nmoves(a))


cases = int(input())
for i in range(cases):
	length = int(input())
	alist = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(length):
		if i % 2 != alist[i] % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


try:
	t = int(input())
	for _ in range(t):
		n = int(input())
		ar = list(map(int, input().split()))
		(even, odd) = (0, 0)
		for i in range(len(ar)):
			if i % 2 == 1 and ar[i] % 2 == 0:
				even += 1
			elif i % 2 == 0 and ar[i] % 2 == 1:
				odd += 1
		if even == 0 and odd == 0:
			print(0)
			continue
		elif even == odd:
			print(even)
			continue
		else:
			print(-1)
			continue
except EOFError as e:
	pass


n = int(input())
for i in range(n):
	a = int(input().rstrip())
	l = list(map(int, input().split()))
	c = d = 0
	for i in range(len(l)):
		if i % 2 != l[i] % 2 and i % 2 == 0:
			c = c + 1
		elif i % 2 != l[i] % 2 and i % 2 == 1:
			d = d + 1
	if c != d:
		print(-1)
	else:
		print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	s = [int(x) for x in input().split()]
	o = 0
	e = 0
	for i in range(n):
		if i & 1 and (not s[i] & 1):
			o += 1
		elif not i & 1 and s[i] & 1:
			e += 1
	if o == e:
		print(o)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	odd = 0
	even = 0
	for i in range(n):
		if arr[i] % 2 != 0:
			odd += 1
		else:
			even += 1
	E = (n + 1) // 2
	O = n - (n + 1) // 2
	ans = -1
	cnt = 0
	for i in range(n):
		if i % 2 != 0 and arr[i] % 2 == 0:
			cnt += 1
		elif i % 2 == 0 and arr[i] % 2 != 0:
			cnt += 1
	if odd == O and even == E:
		ans = cnt // 2
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	lst = input().split()
	for i in range(n):
		lst[i] = int(lst[i])
	count_even = 0
	count_odd = 0
	for i in range(0, n, 2):
		if lst[i] % 2 != 0:
			count_even = count_even + 1
	for i in range(1, n, 2):
		if lst[i] % 2 == 0:
			count_odd = count_odd + 1
	if count_even == count_odd:
		swaps = count_even
	else:
		swaps = -1
	print(int(swaps))


t = int(input())
for _ in range(t):
	n = int(input())
	v = map(int, input().split())
	impar = 0
	par = 0
	for (i, x) in enumerate(v):
		if x & 1 and i & 1 == 0:
			impar += 1
		elif x & 1 == 0 and i & 1:
			par += 1
	if impar != par:
		print(-1)
	else:
		print(impar)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	co = 0
	ce = 0
	for j in range(n):
		if l[j] % 2 == 1 and j % 2 == 0:
			co += 1
		elif l[j] % 2 == 0 and j % 2 == 1:
			ce += 1
	if ce != co:
		print(-1)
	else:
		print(ce)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	cnt = 0
	cnt1 = 0
	cnt2 = 0
	for i in range(n):
		if i % 2 != li[i] % 2:
			cnt += 1
			if li[i] % 2 == 0:
				cnt2 += 1
			else:
				cnt1 += 1
	if cnt % 2 == 0 and cnt1 == cnt2:
		print(cnt // 2)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	l = [0, 0]
	for i in range(n):
		if i & 1 != arr[i] & 1:
			l[i & 1] += 1
	if l[0] == l[1]:
		print(l[0])
	else:
		print(-1)


def solve(a, n):
	d = n // 2
	r = []
	c = 0
	for (i, j) in enumerate(a):
		if i % 2 == 0:
			c += 1 if j % 2 != 0 else 0
		else:
			c += 1 if j % 2 == 0 else 0
		if j % 2 != 0:
			d -= 1
	if d != 0:
		return -1
	return c // 2
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	res = solve(a, n)
	print(res)


for _ in range(int(input())):
	n = int(input())
	data = [int(x) for x in input().split()]
	odd = 0
	even = 0
	for q in range(n):
		if q % 2:
			if data[q] % 2 == 0:
				even += 1
		elif data[q] % 2:
			odd += 1
	if odd != even:
		print(-1)
	else:
		print(even)


t = int(input())
for testcase in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	arr = []
	ind = []
	p = 0
	q = 0
	for k in range(n):
		if l[k] % 2 == 0:
			p = p + 1
		else:
			q = q + 1
		arr.append(l[k] % 2)
		ind.append(k % 2)
	c = 0
	for i in range(n):
		if arr[i] != ind[i]:
			c = c + 1
	if p == q or p == q + 1:
		print(c // 2)
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ct = 0
	od = 0
	even = 0
	for i in range(n):
		k = arr[i] & 1
		if k:
			od += 1
		else:
			even += 1
		if k != i & 1:
			ct += 1
	if n & 1:
		if even - od == 1:
			print(ct // 2)
		else:
			print(-1)
	elif even == od:
		print(ct // 2)
	else:
		print(-1)


for _ in range(int(input())):
	l = int(input())
	l1 = list(map(int, input().split()))
	oc = 0
	ec = 0
	for i in range(0, l, 2):
		if l1[i] % 2 != i % 2:
			ec += 1
	for i in range(1, l, 2):
		if l1[i] % 2 != i % 2:
			oc += 1
	if ec == oc:
		print(ec)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	l1 = []
	for i in range(len(l)):
		if i % 2 != l[i] % 2:
			count += 1
			l1.append(l[i])
	odd = 0
	even = 0
	for i in l1:
		if i % 2 == 0:
			even += 1
		else:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	ch = input()
	L = [int(j) for j in ch.split()]
	comp = 0
	for k in range(n - 1):
		if L[k] % 2 != k % 2:
			x = k + 1
			d = comp
			while d == comp and x < n:
				if L[x] % 2 != x % 2:
					permut = L[k]
					L[k] = L[x]
					L[x] = permut
					comp += 1
				x += 2
	E = set([s for s in range(n) if L[s] % 2 != s % 2])
	if len(E) > 0:
		comp = -1
	print(comp)


for _ in range(int(input())):
	n = int(input())
	mylist = list(map(int, input().split()))[:n]
	notzero = 0
	notone = 0
	i = 0
	while i < n:
		if mylist[i] % 2 != 0:
			notzero += 1
		i += 2
	i = 1
	while i < n:
		if mylist[i] % 2 != 1:
			notone += 1
		i += 2
	if notzero == notone:
		print(notzero)
	else:
		print(-1)


def checkparity(n):
	if n % 2 == 0:
		return 0
	else:
		return 1
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ev = 0
	odd = 0
	for i in range(n):
		if l[i] % 2:
			odd += 1
		else:
			ev += 1
	if n % 2 == 0 and odd != ev:
		print(-1)
		continue
	elif n % 2 and ev != odd + 1:
		print(-1)
		continue
	else:
		count = 0
		for i in range(n):
			if checkparity(i) != checkparity(l[i]):
				count += 1
		print(count // 2)


t = int(input())
for _ in range(0, t):
	n = int(input())
	A = list(map(int, input().split()))
	e = 0
	o = 0
	m = 0
	for i in A:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
	if n % 2 == 0 and e != o or (n % 2 != 0 and e != o + 1):
		print(-1)
	else:
		for i in range(0, n):
			if A[i] % 2 != i % 2:
				m += 1
		print(m // 2)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		if a[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	e = 0
	o = 0
	count = 0
	if n % 2 == 0:
		e = n / 2
		o = n / 2
	else:
		e = n // 2 + 1
		o = n // 2
	if e != even or o != odd:
		print(-1)
	else:
		for i in range(len(a)):
			if i % 2 != a[i] % 2:
				count += 1
		print(count // 2)


from sys import stdin
for case in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = [int(x) % 2 for x in stdin.readline().split()]
	odd = a.count(1)
	if odd != n // 2:
		print(-1)
	else:
		ineq = 0
		for (x, y) in enumerate(a):
			if x % 2 != y:
				ineq += 1
		print(ineq // 2)


for i in range(int(input())):
	ans = 0
	numb_even = 0
	numb_odd = 0
	wrong_even = 0
	wrong_odd = 0
	n = int(input())
	l = list(map(int, input().split()))
	for j in range(n):
		if l[j] % 2 == 0:
			if j % 2 != 0:
				wrong_even += 1
			numb_even += 1
		else:
			if j % 2 == 0:
				wrong_odd += 1
			numb_odd += 1
	if n % 2 == 0:
		if numb_odd != numb_even:
			ans = -1
	elif numb_even != numb_odd - 1:
		ans = -1
	if wrong_odd == wrong_even:
		ans = wrong_even
	else:
		ans = -1
	print(ans)


for q in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(o, e) = (0, 0)
	for x in range(n):
		if x % 2 == 0 and l[x] % 2 == 1:
			o += 1
		elif x % 2 == 1 and l[x] % 2 == 0:
			e += 1
	if o == e:
		print(o)
	else:
		print(-1)


for i in range(int(input())):
	result = even = odd = 0
	n = int(input())
	ls = list(map(int, input().split()))
	for k in range(n):
		if ls[k] % 2 ^ k % 2:
			if k & 1:
				odd += 1
			else:
				even += 1
	print(odd) if even == odd else print(-1)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	odd_ind = 1
	even_ind = 0
	swaps = 0
	while True:
		while even_ind < n and a[even_ind] % 2 == 0:
			even_ind += 2
		while odd_ind < n and a[odd_ind] % 2 == 1:
			odd_ind += 2
		if even_ind < n and odd_ind < n:
			(a[even_ind], a[odd_ind]) = (a[odd_ind], a[even_ind])
			swaps += 1
		else:
			break
	flag = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			flag = 1
	if flag == 1:
		print(-1)
	else:
		print(swaps)
	t -= 1


def solve(arr):
	(even_error, odd_error) = (0, 0)
	check = [0 for _ in range(len(arr))]
	for i in range(len(arr)):
		check[i] = arr[i] % 2
		if arr[i] % 2 != i % 2:
			if i % 2 == 1:
				odd_error += 1
			else:
				even_error += 1
		pass
	pass
	odd = check.count(1)
	even = check.count(0)
	if odd_error == even_error:
		print(even_error)
	else:
		print(-1)
n = int(input())
for _ in range(n):
	length = input()
	arr = [int(x) for x in input().split()]
	solve(arr)
	pass


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	ce = 0
	co = 0
	for i in range(n):
		if i % 2 == 0 and ar[i] % 2 != 0:
			ce = ce + 1
		elif i % 2 != 0 and ar[i] % 2 == 0:
			co = co + 1
	if co == ce:
		print(ce)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	c_even = 0
	for i in range(1, n, 2):
		if arr[i] % 2 == 0:
			c_even += 1
	c_odd = 0
	for i in range(0, n, 2):
		if arr[i] % 2 != 0:
			c_odd += 1
	if c_even == c_odd:
		print(c_odd)
	else:
		print('-1')


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	l1 = 0
	l2 = 0
	c = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if arr[i] % 2 == 1:
				l1 += 1
			else:
				l2 += 1
	if l1 == l2:
		print(l1)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	count1 = 0
	count0 = 0
	l = list(map(int, input().split()))
	for i in range(len(l)):
		if i % 2 != l[i] % 2:
			if l[i] % 2 == 1:
				count1 += 1
			else:
				count0 += 1
	if count1 != count0:
		print(-1)
	else:
		print(count1)


t = int(input())
for _ in range(t):
	l = int(input())
	nums = list(map(int, input().split()))
	(zero, one) = (0, 0)
	for i in nums:
		if i & 1:
			one += 1
		else:
			zero += 1
	if one > zero or one < zero - 1:
		print('-1')
	else:
		nums2 = []
		for i in nums:
			if i % 2 == 0:
				nums2.append(0)
			else:
				nums2.append(1)
		(oneZero, oneOne, ZeroZero, ZeroOne) = (0, 0, 0, 0)
		i = 1
		while i < len(nums2):
			if l & 1 and i == l - 1 and (nums2[i] == 1):
				oneOne += 1
			if nums2[i] == 1 and nums2[i - 1] == 0:
				ZeroOne += 1
			elif nums2[i] == 0 and nums2[i - 1] == 1:
				oneZero += 1
			elif nums2[i] == 1 and nums2[i - 1] == 1:
				oneOne += 1
			elif nums2[i] == 0 and nums2[i - 1] == 0:
				ZeroZero += 1
			i += 2
		res = oneZero + ZeroZero
		print(res)


a = int(input())
for i in range(0, a):
	b = int(input())
	arr = list(map(int, input().split()))
	odd = []
	even = []
	for i in range(0, len(arr)):
		if not i % 2 == arr[i] % 2:
			if arr[i] % 2 == 0:
				even.append(arr[i])
			else:
				odd.append(arr[i])
	if len(odd) == len(even):
		print(len(even))
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	chet = nechet = o = 0
	for j in range(n):
		if s[j] % 2 != j % 2:
			if s[j] % 2 == 0:
				chet += 1
			else:
				nechet += 1
			o += 1
	if o % 2 != 0 or chet != nechet:
		print(-1)
	else:
		print(o // 2)


t = int(input())
inn = []
result = []
e = 0
o = 0
for j in range(t):
	n = int(input())
	inn = [int(a) for a in input().split()]
	for i in range(0, n):
		if i % 2 != inn[i] % 2:
			if i % 2 == 0:
				e = e + 1
			else:
				o = o + 1
	if e == o:
		result.append(o)
	else:
		result.append(-1)
	e = 0
	o = 0
for k in result:
	print(k)


import math

def check(t, h, c, n):
	return abs(t - (n * (h + c) - c) / (2 * n - 1))

def solution():
	n = int(input())
	arr = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 == 0:
			if arr[i] % 2 != 0:
				even += 1
		elif arr[i] % 2 == 0:
			odd += 1
	if odd != even:
		print(-1)
		return
	print(even)
for _ in range(int(input())):
	solution()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	jor = 0
	bijor = 0
	for i in range(n):
		if i % 2 == 0:
			if i % 2 != a[i] % 2:
				jor += 1
		elif i % 2 != a[i] % 2:
			bijor += 1
	if jor != bijor:
		print(-1)
	else:
		print(jor)


import sys

def calculate(numbers):
	invalidOddIdxCount = 0
	invalidEvenIdxCount = 0
	for (idx, rawNumber) in enumerate(numbers):
		number = int(rawNumber)
		if number % 2 == 0:
			if idx % 2 != 0:
				invalidEvenIdxCount += 1
		elif idx % 2 != 1:
			invalidOddIdxCount += 1
	if invalidEvenIdxCount == invalidOddIdxCount:
		return int((invalidEvenIdxCount + invalidOddIdxCount) / 2)
	else:
		return -1
inputs = []
numOfInput = sys.stdin.readline()
for inputIndex in range(0, int(numOfInput)):
	sys.stdin.readline()
	inputs.append(sys.stdin.readline().split(' '))
for lineInput in inputs:
	result = calculate(lineInput)
	print(result)


for _ in range(int(input())):
	n = int(input())
	a = [i % 2 for i in map(int, input().split())]
	if sum(a) != n // 2:
		print(-1)
		continue
	res = 0
	for i in range(0, n, 2):
		res += a[i]
	print(res)


t = int(input())
while t > 0:
	fine = 0
	even = 0
	odd = 0
	n = int(input())
	bad = [int(x) for x in input().split()]
	for i in range(len(bad)):
		if i % 2 == 0:
			if bad[i] % 2 == 0:
				fine += 1
			else:
				even += 1
		elif bad[i] % 2 == 1:
			fine += 1
		else:
			odd += 1
	if fine == len(bad):
		print('0')
	elif odd == even:
		print(even)
	else:
		print('-1')
	t -= 1


test = int(input())
for i in range(test):
	n = int(input())
	even = 0
	odd = 0
	lis = list(map(int, input().split()))
	for i in range(n):
		if lis[i] % 2 != i % 2:
			if i % 2 == 0:
				even = even + 1
			else:
				odd += 1
	if even != odd:
		print(-1)
	else:
		print(even)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	c = 0
	k = 0
	for i in range(n):
		if ar[i] % 2 == 0:
			c += 1
	for j in range(n):
		if ar[j] % 2 != j % 2:
			k += 1
	if n % 2 == 0:
		if n // 2 == c:
			print(k // 2)
		else:
			print(-1)
	elif n % 2 == 1:
		if c * 2 - n == 1:
			print(k // 2)
		else:
			print(-1)
	elif k == 0:
		print(0)


rep = int(input())
for i in range(rep):
	evenCount = 0
	oddCount = 0
	leng = int(input())
	arr = [int(x) for x in input().split()]
	odd = leng % 2 != 0
	for j in range(int(leng / 2)):
		if arr[2 * j] % 2 != 0:
			oddCount = oddCount + 1
		if arr[2 * j + 1] % 2 != 1:
			evenCount = evenCount + 1
	if odd:
		if arr[len(arr) - 1] % 2 != 0:
			oddCount = oddCount + 1
	if evenCount != oddCount:
		print(-1)
	else:
		print(evenCount)


for _ in range(int(input())):
	n = int(input())
	nums = [int(j) for j in input().split()]
	(even, odd) = (0, 0)
	for j in range(n):
		if j % 2 == 0 and nums[j] % 2 == 1:
			odd += 1
		if j % 2 == 1 and nums[j] % 2 == 0:
			even += 1
	if even == odd:
		print(even)
	else:
		print(-1)


def solve(a, lena):
	odd = sum(a)
	if odd == lena // 2:
		minmove = 0
		balance = 0
		for it in range(lena):
			balance = a[it] - it % 2
			if balance != 0:
				minmove += 1
		return minmove // 2
	else:
		return -1
t = int(input())
for test in range(t):
	l = int(input())
	a = [int(i) % 2 for i in input().split()]
	print(solve(a, l))


t = int(input())
for f in range(0, t):
	n = int(input())
	a = input().split()
	m1 = 0
	m2 = 0
	for (i, x) in enumerate(a):
		if i % 2 == 0 and int(x) % 2 == 1:
			m1 += 1
		if i % 2 == 1 and int(x) % 2 == 0:
			m2 += 1
	if m1 == m2:
		print(m1)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	o = 0
	x = 0
	for j in range(n):
		if l[j] % 2 == j % 2:
			l[j] = -1
			o += 1
			continue
		l[j] = l[j] % 2
	n -= o
	if n % 2 == 1:
		print(-1)
	elif l.count(0) == l.count(1):
		print(n // 2)
	else:
		print(-1)


for tc in range(int(input())):
	n = int(input())
	ar = [int(i) for i in input().split()]
	odds = 0
	evens = 0
	for i in range(n):
		if i % 2 == 0 and ar[i] % 2 == 1:
			evens += 1
		if i % 2 == 1 and ar[i] % 2 == 0:
			odds += 1
	if odds == evens:
		print(odds)
	else:
		print(-1)


n = int(input())
for k in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	a = []
	b = []
	for i in range(m):
		c = l[i] % 2
		d = i % 2
		a.append(c)
		b.append(d)
	for i in range(m):
		if a[i] == b[i]:
			a[i] = 2
			b[i] = 2
		else:
			pass
	if a.count(1) == b.count(1) and a.count(0) == b.count(0):
		print(a.count(1))
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	flag = 0
	l = list(map(int, input().split()))
	c_zero = 0
	c_one = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			if i % 2 == 0:
				c_zero = c_zero + 1
			else:
				c_one = c_one + 1
	if c_zero == c_one:
		print(c_zero)
	else:
		print(-1)


for _ in range(int(input())):
	N = int(input())
	List = [int(x) for x in input().split()]
	Even = 0
	Odd = 0
	for i in range(N):
		if i & 1 != List[i] & 1:
			if List[i] & 1:
				Odd += 1
			else:
				Even += 1
	if Even == Odd:
		print(Even)
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	pair = odd = 0
	for i in range(0, n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				pair += 1
				continue
		elif a[i] % 2 != 1:
			odd += 1
	if pair != odd:
		print(-1)
	else:
		print(pair)


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, log2
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0

def def_inf():
	return inf

def atoi(s):
	return ord(s) - ord('0')

def inc(s, n=1):
	return chr((ord(s) - ord('a') + n) % 26 + ord('a'))

class XY:

	def __init__(self, x, y):
		self.x = x
		self.y = y

def rotate(a, b, c):
	ang = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y)
	if ang == 0:
		return 0
	else:
		return ang / abs(ang)

def phi(n):
	(res, p) = (n, 2)
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			res -= res // p
		p += 1
	if n > 1:
		res -= res // n
	return res
for _ in range(iinp()):
	n = iinp()
	a = lmp()
	(ee, eo, oe, oo) = (0, 0, 0, 0)
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 == 0:
				ee += 1
			else:
				eo += 1
		elif a[i] % 2 == 0:
			oe += 1
		else:
			oo += 1
	if oo + eo != n // 2:
		print(-1)
	else:
		print(min(oe, eo))


def f():
	n = int(input(''))
	l = list(map(int, input('').split(' ')))
	c = 0
	d = 0
	for i in l:
		if i % 2 == 0:
			c = c + 1
		else:
			d = d + 1
	if n % 2 == 0:
		if c != d:
			print(-1)
			return
	elif c != d + 1:
		print(-1)
		return
	k = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			k = k + 1
	print(k // 2)
n = int(input(''))
for i in range(n):
	f()


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	o = 0
	e = 0
	mis = 0
	for i in range(n):
		o += arr[i] % 2
		e += (arr[i] + 1) % 2
		if arr[i] % 2 != i % 2:
			mis += 1
	if o == n // 2 and e == n // 2 + n % 2:
		print(mis // 2)
	else:
		print(-1)


test_cases = int(input())
for _ in range(test_cases):
	n = int(input())
	array = [int(i) for i in input().split(' ')]
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 != array[i] % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


t = int(input())
for tp in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	eve = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				eve += 1
		elif l[i] % 2 == 0:
			odd += 1
	if eve == odd:
		print(eve)
	else:
		print(-1)


t = int(input())
arr = []
for _ in range(t):
	even_i = 0
	odd_i = 0
	n = int(input())
	l = list(map(int, input().strip().split()))
	for i in range(n):
		if l[i] % 2 != i % 2:
			if i % 2 == 0:
				even_i += 1
			else:
				odd_i += 1
	if even_i == odd_i:
		arr.append(even_i)
	else:
		arr.append(-1)
for k in arr:
	print(k)


t = int(input())
for testcase in range(t):
	n = int(input())
	ok = 0
	zor = 0
	bizor = 0
	arr = list(map(int, input().split()))
	for i in range(n):
		if i % 2 == arr[i] % 2:
			ok += 1
			continue
		if arr[i] % 2 == 0:
			zor += 1
		else:
			bizor += 1
	if ok == n:
		print('0\n')
	elif zor == bizor:
		print(zor, '\n')
	else:
		print('-1\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	evenCount = 0
	oddCount = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				evenCount += 1
			else:
				oddCount += 1
	if evenCount == oddCount:
		print(evenCount)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	kisuuError = 0
	guusuuError = 0
	for i in range(0, len(a), 2):
		if a[i] % 2 != 0:
			guusuuError += 1
	for i in range(1, len(a), 2):
		if a[i] % 2 != 1:
			kisuuError += 1
	if kisuuError != guusuuError:
		print(-1)
		continue
	print(kisuuError)


t = int(input())
for i in range(t):
	input()
	nums = list(map(int, input().split()))
	even = 0
	odd = 0
	for z in range(len(nums)):
		lhs = z % 2
		rhs = nums[z] % 2
		if lhs == 0 and rhs != 0:
			odd += 1
		elif lhs != 0 and rhs == 0:
			even += 1
	if odd != even:
		print(-1)
	else:
		print(odd)


for T in range(int(input())):
	n = int(input())
	c = 0
	d = 0
	l = list(map(int, input().split()))
	for i in range(len(l)):
		if i % 2 == 0 and l[i] % 2 != 0:
			c += 1
		elif i % 2 != 0 and l[i] % 2 == 0:
			d += 1
	if c == d:
		print(c)
	elif c == 0 and d == 0:
		print('0')
	elif d != c:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	o = 0
	z = 0
	for i in range(len(l)):
		if i % 2 == 0 and l[i] % 2 != 0:
			z += 1
		if i % 2 == 1 and l[i] % 2 != 1:
			o += 1
	if z == o:
		print(z)
	else:
		print(-1)


def get_minimum_swaps(n, a):
	index_parity = []
	value_parity = []
	for i in range(0, n):
		index_parity.append(i % 2)
		value_parity.append(a[i] % 2)
	if sorted(index_parity) == sorted(value_parity):
		if index_parity == value_parity:
			return 0
		else:
			c = 0
			for i in range(len(index_parity)):
				if index_parity[i] != value_parity[i]:
					c = c + 1
			return c // 2
	else:
		return -1
	return 0
t = int(input())
print('\n')
for i in range(1, t + 1):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(get_minimum_swaps(n, a))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(out_evens, out_odds) = (0, 0)
	for i in range(n):
		if i % 2 == arr[i] % 2:
			continue
		elif arr[i] % 2 == 1:
			out_odds += 1
		else:
			out_evens += 1
	if out_odds != out_evens:
		print(-1)
	elif out_odds == 0:
		print(0)
	else:
		print(out_odds)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def solve(t):
	bad_odds = 0
	bad_evens = 0
	for (i, v) in enumerate(t):
		if i % 2 != v % 2:
			if i % 2 == 0:
				bad_odds += 1
			else:
				bad_evens += 1
	if bad_odds == bad_evens:
		print(bad_odds)
	else:
		print(-1)
T = inp()
tests = []
for _ in range(T):
	inp()
	tests.append(inlt())
for t in tests:
	solve(t)


cases = int(input())
for i in range(cases):
	arrays = int(input())
	arrayold = input()
	arraynew = arrayold.split(' ')
	array1 = []
	array2 = []
	arrayt1 = []
	arrayt2 = []
	k = 0
	for j in range(arrays):
		array1.append(j % 2)
		temp = int(arraynew[j])
		array2.append(temp % 2)
		arrayt1.append(j % 2)
		arrayt2.append(temp % 2)
	arrayt1.sort()
	arrayt2.sort()
	if arrayt1 != arrayt2:
		print(-1)
		continue
	else:
		pass
	for h in range(arrays):
		if array1[h] == array2[h]:
			pass
		else:
			k = k + 1
	if k % 2 == 0:
		print(round(k / 2))
	else:
		print(-1)


for r in range(int(input())):
	s = int(input())
	a = list(map(int, input().split()))
	n = 0
	y = 0
	for i in range(s):
		if a[i] % 2 == 0 and i % 2 != 0:
			y = y + 1
		elif a[i] % 2 != 0 and i % 2 == 0:
			n = n + 1
	if y == n:
		print(y)
	else:
		print(-1)


t = int(input())
for x in range(t):
	size = int(input())
	L = [int(i) for i in input().split()]
	(i, even, odd) = (0, 0, 0)
	while i < size:
		if i % 2 == L[i] % 2:
			pass
		elif L[i] % 2 == 1:
			odd += 1
		else:
			even += 1
		i += 1
	if even == odd:
		print(odd)
	else:
		print('-1')


length = int(input())
lst = []
for _ in range(length):
	n = int(input())
	even_count = 0
	odd_count = 0
	count = 0
	lst1 = list(map(int, input().split()))
	for i in lst1:
		if i % 2 == 0:
			even_count += 1
		else:
			odd_count += 1
	if n % 2 == 1:
		if even_count - odd_count != 1:
			lst.append(-1)
		else:
			for j in range(len(lst1)):
				if j % 2 != lst1[j] % 2:
					count += 1
			lst.append(int(count / 2))
	elif even_count - odd_count != 0:
		lst.append(-1)
	else:
		for j in range(len(lst1)):
			if j % 2 != lst1[j] % 2:
				count += 1
		lst.append(int(count / 2))
for val in lst:
	print(val)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(even, odd) = (0, 0)
	for i in range(n):
		lol = i % 2
		if not a[i] % 2 == lol:
			if lol:
				odd += 1
			else:
				even += 1
	if odd != even:
		print(-1)
	else:
		print((odd + even) // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count_even = 0
	count_odd = 0
	ans = []
	for i in range(len(a)):
		if i % 2 == 0 and a[i] % 2 != 0:
			ans.append([i, a[i]])
			count_even += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			count_odd += 1
	if count_even == 0 and count_odd == 0:
		print(0)
	elif count_odd == count_even and (count_even != 0 or count_odd != 0):
		print(count_odd)
	elif count_odd != count_even:
		print(-1)


import sys
get = sys.stdin.readline
tc = int(get())
for _ in range(tc):
	n = int(get())
	arr = list(map(int, get().split()))
	ans = 0
	check = 0
	odd = 0
	even = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if arr[i] % 2 == 0 and i % 2 == 1:
			check += 1
		if arr[i] % 2 == 1 and i % 2 == 0:
			check += 1
	if n % 2 == 0:
		if check % 2 == 0 and odd == even:
			ans = check // 2
		else:
			ans = -1
	elif check % 2 == 0 and even - odd == 1:
		ans = check // 2
	else:
		ans = -1
	print(ans)


def solve(arr, n):
	even = 0
	odd = 0
	good = 0
	for i in range(n):
		item = arr[i]
		if item % 2 == 0:
			even += 1
		else:
			odd += 1
		if i % 2 == item % 2:
			good += 1
	if good == n:
		print('0')
		return
	if n % 2 == 0:
		if even - odd == 0:
			print((n - good) // 2)
		else:
			print('-1')
	elif even - odd == 1:
		print((n - good) // 2)
	else:
		print('-1')
t = int(input())
while t > 0:
	n = int(input())
	arr = [int(_i) for _i in input().strip().split(' ')]
	solve(arr, n)
	t -= 1


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	x = 0
	o = 0
	e = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if a[i] % 2 == 0:
				e += 1
			else:
				o += 1
	if o == e:
		print(o)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(s1, s0) = (0, 0)
	for i in range(n):
		if a[i] % 2 == 0 and i % 2 == 1:
			s0 += 1
		elif a[i] % 2 == 1 and i % 2 == 0:
			s1 += 1
	if s1 == s0:
		print(s1)
	else:
		print(-1)


a = int(input())
for i in range(a):
	b = int(input())
	if b == 1:
		x = int(input())
		if x % 2 == 0:
			print('0')
		else:
			print('-1')
	elif b == 2:
		(y, z) = map(int, input().split())
		if y % 2 == 0 and z % 2 == 1:
			print('0')
		elif y % 2 == 1 and z % 2 == 0:
			print('1')
		else:
			print('-1')
	else:
		l = list(map(int, input().split()))
		(c, d) = ([], [])
		k = 0
		while k < len(l):
			m = k % 2
			n = l[k] % 2
			if m != 0 or n != 0:
				c.append(l[k])
			k += 2
		s = 1
		while s < len(l):
			o = s % 2
			p = l[s] % 2
			if o != p:
				d.append(l[s])
			s += 2
		if len(c) == len(d):
			print(len(c))
		else:
			print('-1')


for _ in range(int(input())):
	k = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in range(k):
		if i % 2 == 0:
			if a[i] % 2 == 0:
				b.append(0)
			else:
				b.append('e')
		elif a[i] % 2 != 0:
			b.append(0)
		else:
			b.append('o')
	m1 = b.count('e')
	m2 = b.count('o')
	if m1 != m2:
		print(-1)
	else:
		print(m1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1:
		print(-1 if arr[0] % 2 == 1 else 0)
	else:
		(odd, even, ans) = (0, 0, 0)
		for (i, j) in enumerate(arr):
			if j % 2 == 0:
				even += 1
			else:
				odd += 1
			if i % 2 == 0 and j % 2 == 1:
				ans += 1
			elif i % 2 == 1 and j % 2 == 0:
				ans += 1
		if (odd + even) % 2 == 0:
			print(-1 if odd != even else ans // 2)
		else:
			print(-1 if even != odd + 1 else ans // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	mod = []
	z = 0
	o = 0
	flag = 0
	move_z = 0
	move_o = 0
	for i in a:
		x = i % 2
		if flag == 0:
			if x != 0:
				move_z += 1
		if flag == 1:
			if x != 1:
				move_o += 1
		mod.append(x)
		if flag == 0:
			flag = 1
		else:
			flag = 0
	if move_z != move_o:
		ans = -1
	else:
		ans = move_z
	print(ans)


import sys
input = sys.stdin.buffer.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	even = 0
	odd = 0
	swap = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			if arr[i] % 2 == 0:
				even += 1
			else:
				odd += 1
				swap += 1
		elif arr[i] % 2 == 1:
			odd += 1
		else:
			even += 1
	if even == odd or odd == even - 1:
		print(swap)
	else:
		print('-1')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	(oo, ee) = (0, 0)
	for i in range(n):
		if l[i] % 2 == 1 and i % 2 == 0:
			oo += 1
		if l[i] % 2 == 0 and i % 2 == 1:
			ee += 1
	if oo == ee:
		print(oo)
	else:
		print(-1)


tc = int(input().strip())
while tc:
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	(ods, evs) = (0, 0)
	for a in arr:
		if a % 2 == 0:
			evs += 1
		else:
			ods += 1
	tevs = n // 2 + n % 2
	tods = n // 2
	if tevs != evs:
		print(-1)
	else:
		cnt = 0
		for i in range(n):
			if i % 2 != arr[i] % 2:
				cnt += 1
		print(cnt // 2)
	tc -= 1


def arrayType(arr):
	odd = 0
	even = 0
	for i in range(len(arr)):
		if arr[i] % 2 != i % 2:
			if arr[i] % 2 > 0:
				odd += 1
			else:
				even += 1
	if len(arr) % 2 != 0:
		evenPos = len(arr) // 2 + 1
		oddPos = len(arr) // 2
	else:
		evenPos = len(arr) // 2
		oddPos = len(arr) // 2 + 1
	if odd > oddPos or even > evenPos or even > odd or (odd > even):
		return -1
	return odd
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(arrayType(arr))


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	(evenMis, oddMis) = (0, 0)
	for i in range(n):
		if arr[i] % 2 != i % 2:
			if i % 2 == 0:
				evenMis += 1
			else:
				oddMis += 1
	if evenMis == oddMis:
		print(evenMis)
	else:
		print(-1)
	t -= 1


def solve(n):
	a = [int(i) for i in input().split()]
	(nch, ch) = (0, 0)
	for i in range(n):
		if a[i] % 2 == 0:
			ch += 1
		else:
			nch += 1
	if ch != n - n // 2 or nch != n // 2:
		print(-1)
		return
	(pch, pnch) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			pnch += 1
		if i % 2 == 1 and a[i] % 2 == 0:
			pch += 1
	if pnch == pch:
		print(pnch)
		return
	print(-1)
for _ in range(int(input())):
	solve(int(input()))


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	cntodd = 0
	cnteven = 0
	for i in range(len(l)):
		if i % 2 == 0 and l[i] % 2 != 0:
			cnteven += 1
		elif i % 2 == 1 and l[i] % 2 != 1:
			cntodd += 1
	if cntodd != cnteven:
		print(-1)
	else:
		print(cnteven)


def check(l, n):
	count = 0
	for i in range(n):
		if i % 2 == l[i] % 2:
			count += 1
	if count == n:
		return 0
	count = 0
	for i in range(0, n):
		if i % 2 != l[i] % 2:
			temp = i + 1
			while temp < n:
				if temp % 2 != l[temp] % 2:
					(l[i], l[temp]) = (l[temp], l[i])
					count += 1
					break
				temp += 2
	C = 0
	for i in range(n):
		if i % 2 == l[i] % 2:
			C += 1
	if C == n:
		return count
	return -1
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(check(l, n))


def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	b_e = 0
	b_o = 0
	for (i, elem) in enumerate(lst):
		if (i - elem) % 2 != 0:
			if i % 2 == 0:
				b_e += 1
			else:
				b_o += 1
	if b_e != b_o:
		print(-1)
	else:
		print(b_e)
t = int(input())
for _ in range(t):
	solve()


n = int(input())
for iterations in range(n):
	l = int(input())
	arr = list(map(int, input().split()))
	even = 0
	odd = 0
	x = 0
	while x < l:
		if x % 2 == 0:
			if arr[x] % 2 != 0:
				even += 1
		elif arr[x] % 2 != 1:
			odd += 1
		x += 1
	if even == odd:
		print(even)
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	line = input().split()
	a = []
	ans = -1
	for i in range(n):
		a.append(int(line[i]))
	cntEven = 0
	cntOdd = 0
	for i in range(n):
		if i % 2 == 1 and a[i] % 2 == 0:
			cntOdd += 1
		if i % 2 == 0 and a[i] % 2 == 1:
			cntEven += 1
	if cntEven == cntOdd:
		ans = cntEven
	print(ans)


t = int(input())
negz = 0
neg = 0
while t > 0:
	t -= 1
	n = input()
	k = list(map(int, input().split()))
	negz = 0
	neg = 0
	for i in range(len(k)):
		if k[i] % 2 == i % 2:
			None
		elif i % 2 == 0:
			negz += 1
		else:
			neg += 1
	if neg == negz and neg == 0:
		print(0)
	elif neg == negz:
		print(neg)
	else:
		print(-1)


t = int(input())
while t > 0:
	t -= 1
	size = int(input())
	arr = list(map(int, input().split(' ')))
	odd = 0
	even = 0
	for i in range(0, size):
		if i % 2 == 1:
			if arr[i] % 2 == 0:
				odd += 1
		elif i % 2 == 0:
			if arr[i] % 2 == 1:
				even += 1
	if odd == even:
		print(odd)
	else:
		print('-1')


for _ in range(int(input())):
	i_liczb = int(input())
	liczby = [int(x) % 2 for x in input().split()]
	(i_par, i_np) = (0, 0)
	i_bled = 0
	for x in range(len(liczby)):
		if x % 2 != liczby[x]:
			i_bled += 1
		if liczby[x] == 0:
			i_par += 1
		else:
			i_np += 1
	if i_par < i_np or i_par >= i_np + 2:
		print(-1)
		continue
	print(i_bled // 2)


t = int(input())
j = 0
while j < t:
	n = int(input())
	a = [int(a) for a in input().split()]
	odd = 0
	even = 0
	for i in range(n):
		if a[i] % 2 == 1 and i % 2 == 0:
			odd += 1
		elif a[i] % 2 == 0 and i % 2 == 1:
			even += 1
	if even != odd:
		print(-1)
	else:
		print(odd)
	j += 1


for case in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	e = []
	o = []
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				e.append(arr[i])
			else:
				o.append(arr[i])
	if len(e) != len(o):
		print(-1)
	else:
		print(len(o))


t = int(input())
for T in range(t):
	n = int(input())
	x = input()
	a = x.split(' ')
	for i in range(len(a)):
		a[i] = int(a[i])
	c = 0
	for i in range(len(a)):
		if a[i] % 2 == 0:
			c = c + 1
	ce = c
	co = len(a) - ce
	if len(a) % 2 == 0:
		if ce == co:
			d = 0
			for i in range(len(a)):
				if i % 2 == 0 and a[i] % 2 != 0:
					d = d + 1
			print(d)
		else:
			print(-1)
	elif ce == co + 1:
		d = 0
		for i in range(len(a)):
			if i % 2 == 0 and a[i] % 2 != 0:
				d = d + 1
		print(d)
	else:
		print(-1)


for mda in range(int(input())):
	n = int(input())
	(even, odd) = (0, 0)
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	if n % 2 == 0 and even != odd or (n % 2 == 1 and even - odd != 1):
		print(-1)
	else:
		ans = 0
		for i in range(n):
			if i % 2 != a[i] % 2:
				for j in range(n):
					if i != j and j % 2 != a[j] % 2 and (a[i] % 2 != a[j] % 2):
						(a[i], a[j]) = (a[j], a[i])
						ans += 1
						break
		print(ans)


INT_MAX = 10 ** 11 + 7
MOD = 10 ** 9 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]
import math
import random as R

def calc(n, A):
	even = 0
	odd = 0
	for i in range(n):
		if i & 1:
			if A[i] % 2 == 0:
				odd += 1
		elif A[i] % 2 != 0:
			even += 1
	if even != odd:
		return -1
	return odd
for _ in range(int(input())):
	n = int(input())
	A = INPUT()
	print(calc(n, A))


def sol(l):
	e = 0
	o = 0
	for x in range(len(l)):
		if x % 2 == 0 and l[x] % 2 != 0:
			o += 1
		elif x % 2 != 0 and l[x] % 2 == 0:
			e += 1
	if e == o:
		return e
	else:
		return -1
t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	v = sol(s)
	print(v)


def solution(a):
	z = []
	b = []
	for i in range(len(a)):
		z.append(i % 2)
		b.append(a[i] % 2)
	c = 0
	for i in range(len(a)):
		if z[i] != b[i]:
			c += 1
	if c % 2 != 0 or sorted(z) != sorted(b):
		print(-1)
	else:
		print(c // 2)
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	solution(l)


for test in range(0, int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	parity = []
	for i in range(0, n):
		if arr[i] % 2 != i % 2:
			parity.append(arr[i])
	if len(parity) % 2 != 0:
		print(-1)
	else:
		even = 0
		odd = 0
		for j in parity:
			if j % 2 == 0:
				even += 1
			else:
				odd += 1
		if even == odd:
			print(even)
		else:
			print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even_count = sum((not _ % 2 for _ in a))
	if not n % 2 and even_count == n // 2 or (n % 2 and even_count == n // 2 + 1):
		swap = sum((i % 2 != a[i] % 2 for i in range(n)))
		print(swap // 2)
	else:
		print('-1')


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
from collections import Counter

def main():
	t = inp()
	for i in range(t):
		n = inp()
		nums = inlt()
		(even, odd) = (0, 0)
		for (i, num) in enumerate(nums):
			if i % 2 != num % 2:
				if i % 2 == 0:
					even += 1
				else:
					odd += 1
		if even != odd:
			print(-1)
		else:
			print(even)
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(eve, eve_wr) = (0, 0)
	(odd, odd_wr) = (0, 0)
	for i in range(len(l)):
		if l[i] % 2 == 0:
			eve += 1
			if i % 2 != 0:
				eve_wr += 1
		else:
			odd += 1
			if i % 2 == 0:
				odd_wr += 1
	if n % 2 == 0:
		if eve != odd:
			print(-1)
		else:
			print(eve_wr)
	elif eve - 1 != odd:
		print(-1)
	else:
		print(eve_wr)


from sys import stdin, stdout

def isValley(i, x):
	return x[i] < x[i + 1] and x[i] < x[i - 1]

def isPeek(i, x):
	return x[i] > x[i + 1] and x[i] > x[i - 1]

def main():
	t = int(stdin.readline())
	ans = [None for i in range(t)]
	for q in range(t):
		n = int(stdin.readline())
		a = [int(x) for x in stdin.readline().split()]
		l = -1
		carry_e = []
		carry_o = []
		amount = 0
		for i in range(n):
			if a[i] % 2 == 0 and i % 2 == 1:
				carry_e.append(a[i])
			elif a[i] % 2 == 1 and i % 2 == 0:
				carry_o.append(a[i])
		if len(carry_e) == len(carry_o):
			ans[q] = len(carry_e)
		else:
			ans[q] = -1
	for i in range(t):
		print(ans[i])
main()


import sys
input = sys.stdin.readline
import math
from collections import defaultdict

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			if i & 1:
				odd += 1
			else:
				even += 1
	print(odd if odd == even else -1)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	od = 0
	c = 0
	for (i, x) in enumerate(a):
		od += x & 1
		if x % 2 != i % 2:
			c += 1
	if od != n // 2:
		print(-1)
	else:
		print(c // 2)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	c = 0
	co = 0
	ce = 0
	for j in range(n):
		if j % 2 == a[j] % 2:
			continue
		else:
			c += 1
			if a[j] % 2 == 0:
				ce += 1
			else:
				co += 1
	if c == 0:
		print(0)
	elif c % 2 == 0 and co == ce:
		print(int(c / 2))
	else:
		print(-1)


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	n = int(fastinput())
	b = list(map(int, fastinput().split()))
	coune = 0
	counto = 0
	for i in range(n):
		if i % 2 == 0 and b[i] % 2 != 0:
			coune += 1
		elif i % 2 == 1 and b[i] % 2 != 1:
			counto += 1
		else:
			continue
	if counto == coune:
		print(coune)
	else:
		print(-1)


numOfInput = input()
for lineInput in range(0, int(numOfInput)):
	totalSecondInput = int(input())
	secondInput = input().split(' ')
	invalidOddIdxCount = 0
	invalidEvenIdxCount = 0
	for idx in range(totalSecondInput):
		number = int(secondInput[idx])
		if number % 2 == 0:
			if idx % 2 != 0:
				invalidEvenIdxCount += 1
		elif idx % 2 != 1:
			invalidOddIdxCount += 1
	if invalidEvenIdxCount == invalidOddIdxCount:
		print(int((invalidEvenIdxCount + invalidOddIdxCount) / 2))
	else:
		print(-1)


def f(arr):
	(a, b) = (0, 0)
	for i in range(0, n, 2):
		if arr[i] % 2 == 0:
			continue
		else:
			a += 1
	for i in range(1, n, 2):
		if arr[i] % 2 != 0:
			continue
		else:
			b += 1
	if a == b:
		return a
	else:
		return -1
for w in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	print(f(arr))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	missed_odds = 0
	missed_evens = 0
	for (i, val) in enumerate(arr):
		i_odd = i % 2
		val_odd = val % 2
		if i_odd == 1 and val_odd == 0:
			missed_evens += 1
		elif i_odd == 0 and val_odd == 1:
			missed_odds += 1
	if missed_odds != missed_evens:
		print('-1')
	elif not missed_odds and (not missed_evens):
		print('0')
	else:
		print(missed_odds)


t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	flag = True
	for i in range(len(lst)):
		if i % 2 == 0 and lst[i] % 2 != 0:
			count1 += 1
		elif i % 2 != 0 and lst[i] % 2 == 0:
			count2 += 1
	if count1 != count2:
		print('-1')
	else:
		print(count1)


import sys
sys.setrecursionlimit(10000)
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	even = 0
	for (ind, no) in enumerate(a):
		if ind % 2 != no % 2:
			if ind % 2 == 1:
				odd += 1
			else:
				even += 1
	if odd != even:
		print('-1')
	else:
		print(odd)


t = int(input())
for _ in range(t):
	n = int(input())
	d = {0: 0, 1: 0}
	l = list(map(int, input().split()))
	counto = n // 2
	countz = n - counto
	mis = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			mis += 1
		d[l[i] % 2] += 1
	if d[0] == countz and d[1] == counto:
		print(mis // 2)
	else:
		print(-1)


k = int(input())
for _ in range(k):
	n = int(input())
	val = list(map(int, input().split()))
	(ev, od) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and val[i] % 2 != 0:
			ev += 1
		if i % 2 != 0 and val[i] % 2 == 0:
			od += 1
	if not abs(ev - od):
		print(ev)
	else:
		print('-1')


for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	if n % 2 == 0:
		ne = n // 2
		no = n // 2
	else:
		ne = n // 2 + 1
		no = n // 2
	counte = 0
	counto = 0
	swap = 0
	for i in range(0, n):
		if a[i] % 2 == 0:
			counte += 1
		else:
			counto += 1
		if i % 2 == 0 and a[i] % 2 != 0:
			swap += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			swap += 1
	if counte == ne and counto == no:
		print(swap // 2)
	else:
		print(-1)


for i in range(int(input())):
	l = int(input())
	a = list(map(int, input().split()))
	e = 0
	o = 0
	for x in range(l):
		if a[x] % 2 != 0 and x % 2 == 0:
			o += 1
		if a[x] % 2 == 0 and x % 2 != 0:
			e += 1
	if o == e:
		print(o)
	else:
		print(-1)


def even(n):
	for i in range(n):
		x = int(input())
		list_1 = list(map(int, input().split()))
		counter = 0
		even_count = 0
		odd_count = 0
		for i in range(len(list_1)):
			if list_1[i] % 2 == 0:
				even_count += 1
			else:
				odd_count += 1
		if even_count < odd_count:
			print(-1)
		elif abs(even_count - odd_count) > 1:
			print(-1)
		else:
			for i in range(len(list_1)):
				if list_1[i] % 2 == 0 and i % 2 != 0:
					counter += 1
				elif list_1[i] % 2 != 0 and i % 2 == 0:
					counter += 1
			print(counter // 2)
n = int(input())
even(n)


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 0
	misEven = 0
	misOdd = 0
	while i < n:
		if arr[i] % 2 != 0:
			misEven += 1
		i += 2
	i = 1
	while i < n:
		if arr[i] % 2 == 0:
			misOdd += 1
		i += 2
	if misOdd == misEven:
		print(misOdd)
	else:
		print(-1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	L = list(map(int, input().split()))
	even = 0
	odd = 0
	for i in range(n):
		val = L[i] & 1
		if i & 1 != val:
			if val == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	zeroind = 0
	zeroval = 0
	oneind = 0
	oneval = 0
	arr = list(map(int, input().strip().split()))
	for i in range(0, n):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				zeroind += 1
			else:
				oneind += 1
			if arr[i] % 2 == 0:
				zeroval += 1
			else:
				oneval += 1
	if zeroval == oneind and zeroind == oneval and (zeroind == oneind):
		print(zeroind)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	ev = 0
	od = 0
	ma = 0
	for j in range(len(ls)):
		if ls[j] % 2 == 0:
			ev += 1
		else:
			od += 1
		if ls[j] % 2 != j % 2:
			ma += 1
	if ev == od or ev - 1 == od:
		print(ma // 2)
	else:
		print(-1)


size = int(input())
for x in range(size):
	num = []
	even = 0
	odd = 0
	wrong = 0
	n = int(input())
	nums = input().split()
	for j in range(n):
		num.append(int(nums[j]))
	counter = 0
	for j in range(n):
		if num[j] % 2 == 0:
			even += 1
			if j % 2 != 0:
				wrong += 1
		else:
			odd += 1
			if j % 2 == 0:
				wrong += 1
	if even - odd < 0:
		print(-1)
	elif even - odd == 0 and wrong == 0:
		print(0)
	elif n == 1 and num[0] % 2 == 0:
		print(0)
	elif even > n // 2 + 1 or odd > n // 2 + 1 or even == n or (odd == n):
		print(-1)
	elif abs(odd - even) > 1:
		print(-1)
	elif wrong % 2 == 0:
		print(wrong // 2)
	else:
		print(wrong // 2 + 1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	should_odd = 0
	should_even = 0
	for i in range(len(a)):
		if i % 2 == 0:
			if a[i] % 2 == 1:
				should_even += 1
		elif a[i] % 2 == 0:
			should_odd += 1
	if should_odd == should_even:
		print(should_even)
	else:
		print(-1)


for x in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	l2 = []
	for x in range(n):
		if x % 2 != l[x] % 2:
			if x % 2 == 0:
				l1.append(x)
			else:
				l2.append(x)
	if len(l2) == len(l1):
		print(len(l1))
	else:
		print(-1)


import math
t = int(input())
while t != 0:
	n = int(input())
	l = [int(i) for i in input().split()]
	(evenwr, oddwr) = (0, 0)
	if n == 1 and l[0] % 2 != 0:
		print(-1)
	else:
		for i in range(len(l)):
			if i % 2 == 0:
				if i % 2 != l[i] % 2:
					evenwr += 1
			elif i % 2 != l[i] % 2:
				oddwr += 1
		if evenwr == oddwr:
			print(evenwr)
		else:
			print(-1)
	t -= 1


test_cases = int(input())
for i in range(test_cases):
	length_of_array = int(input())
	array = [int(i) for i in input().split()]
	even_elements_out_of_place = 0
	if 0 <= len([i for i in array if i % 2 == 0]) - len([i for i in array if i % 2 == 1]) <= 1:
		for i in range(0, len(array), 2):
			if array[i] % 2 != 0:
				even_elements_out_of_place += 1
		print(even_elements_out_of_place)
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	array = list(map(int, input().split()))
	for i in range(n):
		array[i] = array[i] % 2
	zeros = array.count(0)
	ones = array.count(1)
	if zeros == ones or zeros - 1 == ones:
		for i in range(0, n, 2):
			if array[i] == 1:
				c += 1
		print(c)
	else:
		print(-1)


n = int(input())
for i in range(n):
	m = int(input())
	a = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	for i in range(len(a)):
		if i % 2 == 0 and a[i] % 2 == 1:
			count1 += 1
		if i % 2 == 1 and a[i] % 2 == 0:
			count2 += 1
	if count1 != count2:
		print('-1')
	else:
		print((count1 + count2) // 2)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	counte = 0
	counto = 0
	for i in range(N):
		if A[i] % 2 != i % 2:
			if A[i] % 2 == 0:
				counte += 1
			else:
				counto += 1
	if counte == 0 and counto == 0:
		print(0)
	elif counte == counto:
		print(counte)
	else:
		print(-1)


for _ in range(int(input())):
	s = int(input())
	l = [int(x) for x in input().split()]
	e = 0
	o = 0
	for i in range(0, s):
		if l[i] % 2 != i % 2:
			if i % 2 == 0:
				e += 1
			else:
				o += 1
	if e == o:
		print(e)
	else:
		print(-1)


import math
for i in range(int(input())):
	n = int(input())
	(even, odd) = (0, 0)
	c = 0
	A = [int(i) for i in input().split()]
	for i in range(n):
		if A[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if i % 2 != A[i] % 2:
			c += 1
	if n % 2 == 0:
		if even == odd:
			print(math.ceil(c / 2))
		else:
			print(-1)
	elif even == odd + 1:
		print(math.ceil(c / 2))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k1 = 0
	k2 = 0
	for i in range(0, len(a), 2):
		if a[i] % 2 != 0:
			k1 += 1
	if len(a) > 1:
		for i in range(1, len(a), 2):
			if k2 > k1:
				break
			elif a[i] % 2 == 0:
				k2 += 1
	if k1 == k2:
		print(k1)
	else:
		print(-1)


def findeven(a, i):
	j = i + 1
	while j <= len(a) - 1 and (not (a[j] & 1 == 0 and j & 1)):
		j += 1
	if j <= len(a) - 1 and a[j] & 1 == 0 and j & 1:
		return j
	else:
		return -1

def findodd(a, i):
	k = i + 1
	while k <= len(a) - 1 and (not (a[k] & 1 and k & 1 == 0)):
		k += 1
	if k <= len(a) - 1 and a[k] & 1 and (k & 1 == 0):
		return k
	else:
		return -1
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if len(a) == 1:
		if a[0] & 1:
			print(-1)
		else:
			print(0)
	else:
		cnt = 0
		for i in range(len(a)):
			if i & 1 == a[i] & 1:
				continue
			else:
				if i & 1 == 0 and a[i] & 1:
					e = findeven(a, i)
					if e != -1:
						(a[e], a[i]) = (a[i], a[e])
						cnt += 1
					else:
						cnt = -1
						break
				if i & 1 and a[i] & 1 == 0:
					o = findodd(a, i)
					if o != -1:
						(a[o], a[i]) = (a[i], a[o])
						cnt += 1
					else:
						cnt = -1
						break
		print(cnt)


import sys
import math
from collections import *

def get_ints():
	return map(int, input().split())

def get_list():
	return list(get_ints())

def printspx(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
MODPRIME = int(1000000000.0 + 7)
BABYMODPR = 998244353
MAXN = int(100000.0)
for _testcases_ in range(int(input())):
	n = int(input())
	li = get_list()
	odd = even = 0
	for i in range(n):
		if i % 2 != li[i] % 2:
			if li[i] & 1:
				odd += 1
			else:
				even += 1
	if odd != even:
		print(-1)
	else:
		print(odd)


t = int(input())
for q in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	oae = 0
	eao = 0
	for x in range(n):
		if a[x] % 2 == 0 and x % 2 == 1:
			eao += 1
		elif a[x] % 2 == 1 and x % 2 == 0:
			oae += 1
	if eao == oae:
		print(eao)
	else:
		print(-1)


import sys
input = sys.stdin.buffer.readline
T = int(input())
for testcase in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	p = 0
	q = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			p += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			q += 1
	if p == q:
		print(p)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	c = []
	count1 = 0
	count2 = 0
	for i in range(len(a)):
		if i % 2 == 0:
			b.append(a[i])
		else:
			c.append(a[i])
	for i in range(len(b)):
		if b[i] % 2 != 0:
			count1 = count1 + 1
	for i in range(len(c)):
		if c[i] % 2 == 0:
			count2 = count2 + 1
	if count1 == count2:
		print((count1 + count2) // 2)
	else:
		print('-1')


t = int(input())
for k in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list()
	l2 = list()
	x = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			l1.append(i % 2)
			l2.append(l[i] % 2)
	if len(l1) == 0:
		print(0)
	else:
		c = 0
		for i in l1:
			if i in l2:
				l2.remove(i)
				c += 1
			else:
				print('-1')
				break
		else:
			print(c // 2)


t = int(input())
while t:
	n = int(input())
	l1 = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	count = 0
	for i in range(0, n):
		if l1[i] % 2 != i % 2:
			if i % 2 == 1:
				count1 = count1 + 1
			else:
				count2 = count2 + 1
			count = count + 1
	if count % 2 == 1:
		print(-1)
	elif count1 != count2:
		print(-1)
	else:
		print(int(count / 2))
	t = t - 1


def solve(n, nums):
	odd = even = swaps = 0
	for i in range(n):
		if nums[i] % 2 == 0:
			even += 1
			if i % 2 != 0:
				swaps += 1
		else:
			odd += 1
			if i % 2 == 0:
				swaps += 1
	if abs(odd - even) > 1:
		return -1
	if swaps % 2 != 0:
		return -1
	return swaps // 2
t = int(input())
while t:
	n = int(input())
	nums = list(map(int, input().split()))
	print(solve(n, nums))
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	ce = 0
	co = 0
	l = [int(x) for x in input().split()]
	for i in range(n):
		if l[i] % 2 != i % 2:
			if i % 2 == 0:
				ce += 1
			else:
				co += 1
	if ce == co:
		print(ce)
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	flag = True
	count = 0
	odd = 0
	even = 0
	for i in range(n):
		if flag:
			if arr[i] % 2 == 1:
				odd += 1
			flag = False
		else:
			if arr[i] % 2 == 0:
				even += 1
			flag = True
		if odd > 0 and even > 0:
			count += 1
			odd -= 1
			even -= 1
	if odd > 0 or even > 0:
		count = -1
	print(count)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	evens = 0
	for i in a:
		if i % 2 == 0:
			evens += 1
	if evens != (n + 1) // 2:
		print(-1)
		continue
	ans = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			ans += 1
	print(ans // 2)


n = int(input())
for _ in range(n):
	t = int(input())
	a = list(map(int, input().split()))
	count = 0
	count1 = 0
	for i in range(0, len(a)):
		if a[i] % 2 == 1 and i % 2 == 0:
			count = count + 1
		elif a[i] % 2 == 0 and i % 2 == 1:
			count1 += 1
	if count == count1:
		print(count)
	else:
		print(-1)


t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	flag = 0
	ce = 0
	co = 0
	for i in l[::2]:
		if i % 2 == 1:
			ce += 1
	for i in l[1::2]:
		if i % 2 == 0:
			co += 1
	if ce != co:
		ans.append(str(-1))
	else:
		ans.append(str(ce))
print('\n'.join(ans))


import os
import math

def solution():
	t = int(input())
	while t > 0:
		n = int(input())
		k = list(map(int, input().split()))
		count = 0
		co = 0
		ce = 0
		for i in range(len(k)):
			if i & 1:
				if k[i] & 1:
					continue
				co += 1
				count += 1
			elif i & 1 ^ 1:
				if k[i] & 1 ^ 1:
					continue
				ce += 1
				count += 1
		if count & 1:
			print(-1)
		elif count & 1 ^ 1:
			if ce == co:
				print(count // 2)
			else:
				print(-1)
		else:
			print(0)
		t -= 1
solution()


import math, string, itertools, operator, fractions, heapq, collections, re, array, bisect, sys, functools

def solve(line):
	n = int(line)
	a = [int(x) for x in sys.stdin.readline().rstrip().split()]
	cn = [0, 0]
	for i in range(n):
		if i % 2 != a[i] % 2:
			cn[i % 2] += 1
	return cn[0] if cn[0] == cn[1] else -1
T = int(sys.stdin.readline())
t = 0
while True:
	line = sys.stdin.readline().rstrip()
	if not line:
		break
	print(solve(line))
	t += 1


for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	nech = 0
	chet = 0
	never = 0
	for i in range(n):
		if a[i] % 2 == 0:
			chet += 1
			if i % 2 != 0:
				never += 1
		elif a[i] % 2 != 0:
			nech += 1
			if i % 2 == 0:
				never += 1
	if nech != n // 2:
		print(-1)
	else:
		print(never // 2)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ev = []
	od = []
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			ev.append(a[i])
		elif i % 2 == 1 and a[i] % 2 == 0:
			od.append(a[i])
	if len(ev) != len(od):
		print(-1)
	else:
		print(len(ev))


def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	ne = 0
	bad_e = 0
	bad_ne = 0
	for (i, x) in enumerate(a):
		if x % 2 == 1:
			ne += 1
			if i % 2 == 0:
				bad_ne += 1
		elif i % 2 == 1:
			bad_e += 1
	if ne != n // 2:
		return -1
	if bad_e != bad_ne:
		return -1
	return bad_e
for _ in range(int(input())):
	print(main())


import sys
from fractions import gcd
from math import ceil, sqrt, sin, pi, tan
from collections import defaultdict
read = input
import heapq
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
for _t in range(cin()):
	n = cin()
	a = li()
	(ev, od) = (0, 0)
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 0:
				ev += 1
			else:
				od += 1
	if ev != od:
		print(-1)
	else:
		print(ev)


for t in range(int(input())):
	n = int(input())
	odds = n // 2
	arr = list(map(int, input().split()))
	c = 0
	o = 0
	for i in range(n):
		if arr[i] % 2 != i % 2:
			c += 1
		if arr[i] % 2 == 1:
			o += 1
	if odds == o:
		if c % 2 == 0:
			print(c // 2)
		else:
			print(-1)
	else:
		print(-1)


def taskB():
	n = int(input())
	for k in range(n):
		size = int(input())
		line = input()
		arr = list(map(int, line.split(' ')))
		(error_even, error_odd) = (0, 0)
		answer = 0
		for i in range(size):
			if i % 2 == arr[i] % 2:
				continue
			elif arr[i] % 2 == 0 and error_odd > 0:
				error_odd -= 1
				answer += 1
			elif arr[i] % 2 == 1 and error_even > 0:
				error_even -= 1
				answer += 1
			elif arr[i] % 2 == 0:
				error_even += 1
			else:
				error_odd += 1
		if error_odd == 0 and error_even == 0:
			print(answer)
		else:
			print(-1)
taskB()


def check_array(arr):
	calc_diff_chet = 0
	calc_diff_nechet = 0
	for (i, elem) in enumerate(arr):
		if elem % 2 != i % 2:
			if elem % 2 == 0:
				calc_diff_chet += 1
			else:
				calc_diff_nechet += 1
	diff = calc_diff_chet - calc_diff_nechet
	if not diff:
		return calc_diff_chet
	else:
		return -1
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = check_array(arr)
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = 0
	nd = 0
	bad = 0
	for i in range(n):
		if a[i] % 2 == 0:
			d += 1
		else:
			nd += 1
		if (a[i] - i) % 2 != 0:
			bad += 1
	if n % 2 == 0:
		if d != nd:
			print(-1)
		else:
			print(bad // 2)
	elif nd != d - 1:
		print(-1)
	else:
		print(bad // 2)


def help():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	ev = []
	od = []
	for i in range(n):
		if arr[i] % 2 == 1:
			if arr[i] % 2 != i % 2:
				od.append(i)
		elif arr[i] % 2 != i % 2:
			ev.append(i)
	if len(ev) == len(od):
		print(len(ev))
	else:
		print(-1)
for _ in range(int(input())):
	help()


for i in range(int(input())):
	l = 0
	e = 0
	o = 0
	n = int(input())
	a = list(map(int, input().split()))
	for j in range(len(a)):
		if a[j] % 2 == 0:
			e = e + 1
		else:
			o = o + 1
		if j % 2 != 0 and a[j] % 2 == 0 or (j % 2 == 0 and a[j] % 2 != 0):
			l = l + 1
	if n % 2 == 0:
		if e != o:
			print(-1)
		elif l % 2 == 0:
			print(l // 2)
		else:
			print(-1)
	elif e != o + 1:
		print(-1)
	elif l % 2 == 0:
		print(l // 2)
	else:
		print(-1)


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 998244353

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k))))
from collections import deque, defaultdict
import heapq
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def dfs(g, timeIn, timeOut, depths, parents):
	cnt = 0
	stack = [[1, 0, 0, 0]]
	while stack:
		(v, neig_i, parent, depth) = stack[-1]
		parents[v] = parent
		depths[v] = depth
		if neig_i == 0:
			timeIn[v] = cnt
			cnt += 1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i += 1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u, 0, v, depth + 1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1

def isAncestor(u: int, v: int, timeIn: list, timeOut: list) -> str:
	return timeIn[u] <= timeIn[v] and timeOut[v] <= timeOut[u]
cnt = 0

@bootstrap
def dfs(v, adj, timeIn, timeOut, depths, parents, parent=0, depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt += 1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u, adj, timeIn, timeOut, depths, parents, v, depth + 1)
	timeOut[v] = cnt
	cnt += 1
	yield

def solution(a, n):
	(bado, bade) = (0, 0)
	for i in range(n):
		if i % 2 == 1 and a[i] % 2 == 0:
			bado += 1
		if i % 2 == 0 and a[i] % 2 == 1:
			bade += 1
	if bado == bade:
		return bado
	return -1

def main():
	T = 1
	T = ri()
	for i in range(T):
		n = ri()
		a = ria()
		x = solution(a, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	wr_even = 0
	wr_odd = 0
	change = 0
	for (i, a) in enumerate(A):
		if i % 2 != a % 2:
			change += 1
			if a % 2:
				wr_even += 1
			else:
				wr_odd += 1
	if wr_odd != wr_even:
		print(-1)
	else:
		print(wr_odd)


import sys
inp = [int(x) for x in sys.stdin.read().split()]
ii = 0
ttt = inp[ii]
ii += 1
for _ in range(ttt):
	cnt = [0] * 2
	n = inp[ii]
	ii += 1
	for i in range(n):
		x = inp[ii]
		ii += 1
		if x % 2 != i % 2:
			cnt[i % 2] += 1
	print(cnt[0] if cnt[0] == cnt[1] else -1)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt1 = 0
	cnt0 = 0
	for j in range(n):
		if j & 1 == a[j] & 1:
			continue
		if j & 1:
			cnt1 += 1
		else:
			cnt0 += 1
	if cnt1 != cnt0:
		print('-1')
	else:
		print(cnt1)


t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	o = 0
	m = 0
	for i in range(n):
		if l[i] & 1:
			if not i & 1:
				m += 1
			o += 1
	if n // 2 != o:
		print(-1)
	else:
		print(m)


t = int(input())
c = []
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	x = 0
	y = 0
	for i in range(0, n, 2):
		if a[i] % 2 != 0:
			x += 1
	for i in range(1, n, 2):
		if a[i] % 2 == 0:
			y += 1
	if x == y:
		c.append(x)
	else:
		c.append(-1)
for k in c:
	print(k)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	even = 0
	odd = 0
	ceven = 0
	codd = 0
	for (i, x) in enumerate(arr):
		if x % 2 == 0:
			even += 1
			if (x - i) % 2 == 0:
				ceven += 1
		else:
			odd += 1
			if (x - i) % 2 == 0:
				codd += 1
	if even == odd or even == odd + 1:
		if even - ceven == odd - codd:
			print(even - ceven)
		else:
			print(-1)
	else:
		print(-1)


for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(ev, od) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				od += 1
		elif l[i] % 2 == 0:
			ev += 1
	if ev == od:
		print(ev)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(zeroes, ones) = (0, 0)
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if arr[i] % 2 == 0:
				zeroes += 1
			else:
				ones += 1
	if ones != zeroes:
		print(-1)
	else:
		print(ones)


Test = int(input())
while Test > 0:
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	y = 0
	for i in range(0, n, 2):
		if a[i] % 2 != 0:
			x += 1
	for i in range(1, n, 2):
		if a[i] % 2 == 0:
			y += 1
	if x == y:
		print(x)
	else:
		print(-1)
	Test -= 1


n = int(input())
for w in range(n):
	a = int(input())
	l = list(map(int, input().split()))
	(c, k1, k2) = (0, 0, 0)
	for i in range(a):
		if i % 2 != l[i] % 2:
			c += 1
			if i % 2 == 0:
				k1 += 1
			else:
				k2 += 1
	if c == 0:
		print(0)
	elif c == 1:
		print(-1)
	elif k1 == k2:
		print(k1)
	else:
		print(-1)


from fractions import Fraction
import bisect
import os
import io
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for _ in range(t):
	n = iinput()
	a = rlinput()
	even = 0
	odd = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2:
				odd += 1
			else:
				even += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ccTrue = 0
	ccFalse = 0
	lis = []
	evparity = 0
	odparity = 0
	for j in range(n):
		if j % 2 == l[j] % 2:
			ccTrue += 1
		else:
			ccFalse += 1
			lis.append(j)
		if l[j] % 2 == 0:
			evparity += 1
		else:
			odparity += 1
	if n % 2 == 0:
		if evparity == odparity:
			print(ccFalse // 2)
		else:
			print(-1)
	elif evparity == odparity + 1:
		print(ccFalse // 2)
	else:
		print(-1)


for _ in range(int(input())):
	sz = int(input())
	l = list(map(int, input().split()))
	condn = True
	even = 0
	odd = 0
	for i in range(sz):
		if i % 2 == 0 and l[i] % 2 == 0 or (i % 2 != 0 and l[i] % 2 != 0):
			continue
		else:
			condn = False
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if condn == False:
		if odd == even:
			print(odd)
		else:
			print(-1)
	elif condn == True:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	oddAtEven = 0
	evenAtOdd = 0
	for i in range(len(arr)):
		if i % 2 == 0 and arr[i] % 2 != 0:
			oddAtEven += 1
		elif i % 2 == 1 and arr[i] % 2 == 0:
			evenAtOdd += 1
	if oddAtEven != evenAtOdd:
		print(-1)
	else:
		print(evenAtOdd)


test = int(input())
while test != 0:
	test -= 1
	n = int(input())
	l = list(map(int, input().split()))
	e = []
	o = []
	for i in range(n):
		if i % 2 != l[i] % 2:
			if i % 2 == 0:
				e.append(i)
			else:
				o.append(i)
	if len(e) != len(o):
		print(-1)
	else:
		print(len(e))


n = int(input())
for i in range(n):
	(ebo, obe) = (int(0), int(0))
	t = int(input())
	s = input().split()
	for x in range(0, len(s)):
		if int(s[x]) % 2 != 0 and x % 2 == 0:
			obe += 1
		elif int(s[x]) % 2 == 0 and x % 2 != 0:
			ebo += 1
	if ebo == obe:
		print((ebo + obe) // 2)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	x = [int(x) for x in input().split()]
	(even, odd) = ([], [])
	for i in range(n):
		if i % 2 == x[i] % 2:
			continue
		elif i % 2 == 0:
			even.append(x[i] % 2)
		else:
			odd.append(x[i] % 2)
	if len(odd) == len(even) and even.count(1) == odd.count(0):
		print(even.count(1))
	else:
		print(-1)


for _ in range(int(input())):
	N = int(input())
	arr = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(0, len(arr)):
		if i % 2 == 0:
			if arr[i] % 2 != 0:
				even += 1
		elif arr[i] % 2 != 1:
			odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	(odd, even) = ([], [])
	for i in range(n):
		if i % 2 == 0:
			even.append(arr[i])
		else:
			odd.append(arr[i])
	fodd = len([n for n in odd if n % 2 == 0])
	feven = len([n for n in even if n % 2 != 0])
	if fodd == feven:
		print(fodd)
	else:
		print(-1)


q = int(input())
for _ in range(q):
	n = int(input())
	dat = list(map(int, input().split()))
	errorEvenNum = 0
	errorOddNum = 0
	for i in range(n):
		if i % 2 == 0:
			if dat[i] % 2 == 1:
				errorEvenNum += 1
		elif dat[i] % 2 == 0:
			errorOddNum += 1
	if n == 1:
		if dat[0] % 2 == 0:
			print(0)
		else:
			print(-1)
	elif n % 2 == 0:
		if errorEvenNum == errorOddNum:
			print(errorOddNum)
		else:
			print(-1)
	elif errorEvenNum == errorOddNum:
		print(errorOddNum)
	else:
		print(-1)


ncases = int(input())
ans = []
for i in range(ncases):
	length = int(input())
	array = input().split(' ')
	arr = []
	for a in array:
		arr.append(int(a))
	odd = 0
	even = 0
	for i in range(0, len(arr), 2):
		ele = arr[i]
		if ele % 2 != 0:
			even += 1
	for j in range(1, len(arr), 2):
		ele = arr[j]
		if ele % 2 != 1:
			odd += 1
	if odd == even:
		if odd == 0:
			ans.append(0)
		else:
			ans.append(int((odd + even) / 2))
	else:
		ans.append(-1)
for a in ans:
	print(a)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a_false = [0 if a[i] % 2 == i % 2 else 1 for i in range(n)]
	if n == 1:
		if a[0] % 2 == 0:
			print(0)
		else:
			print(-1)
		continue
	tmp = [i for i in range(n)]
	f_odd = a_false[1::2]
	f_even = a_false[0::2]
	if sum(f_odd) == sum(f_even):
		print(sum(f_odd))
	else:
		print(-1)


def a():
	n = int(input(''))
	for i in range(0, n, 1):
		m = int(input(''))
		l = []
		k = 0
		z = 0
		l = list(map(int, input().split()))
		for j in range(0, m, 1):
			if j % 2 == 0:
				if l[j] % 2 != 0:
					k = k + 1
			elif l[j] % 2 == 0:
				z = z + 1
		if k == z:
			print(k)
		else:
			print('-1')
a()


for i in range(int(input())):
	length = int(input())
	l = enumerate(list(map(int, input().split())))
	(a, b) = (0, 0)
	for (e, i) in l:
		if e % 2 == i % 2 and e % 2 == 0:
			a += 1
		elif e % 2 == i % 2 and e % 2 == 1:
			b += 1
	print(-1 if a - length % 2 != b else (length - a - b) // 2)


for _ in ' ' * int(input()):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	cntodd = 0
	cnteven = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2:
				cntodd += 1
			else:
				cnteven += 1
			cnt += 1
	if cnt % 2:
		print(-1)
	elif cntodd == cnteven:
		print(cnt // 2)
	else:
		print(-1)


for i in range(int(input())):
	(n, arr) = (int(input()), list(map(int, input().split(' '))))
	(sum1, sum2) = (0, 0)
	for j in range(n):
		if arr[j] % 2 != j % 2 == 1:
			sum1 += 1
		elif arr[j] % 2 != j % 2 == 0:
			sum2 += 1
	print(sum1 if sum1 == sum2 else -1)


import sys
scan = sys.stdin.readline
from math import *
from random import randint
ttt = int(scan())
test = 1
for test in range(ttt):
	n = int(scan())
	cnt = 0
	jassala = 0
	a = scan()
	ara = a.split()
	for i in range(n):
		if int(ara[i]) % 2 != i % 2:
			jassala = jassala + 1
		if int(ara[i]) % 2 == 0:
			cnt = cnt + 1
	if cnt < n - cnt or abs(n - cnt - cnt) > 1:
		print('-1')
	else:
		print(int(jassala / 2))


for _ in range(int(input())):
	(_, array) = (input(), list(map(int, input().split())))
	(wrong_even, wrong_odd) = (0, 0)
	for (index, number) in enumerate(array):
		if index % 2 == 0 and number % 2 != 0:
			wrong_even += 1
		elif index % 2 != 0 and number % 2 == 0:
			wrong_odd += 1
	print(wrong_even) if wrong_even == wrong_odd else print(-1)


import os
import sys
import math
from collections import defaultdict
from io import BytesIO, IOBase

def power(x, n, m):
	x %= m
	res = 1
	while n != 0:
		if n & 1 == 1:
			res = res * x % m
		x = x * x % m
		n >>= 1
	return res

def mode(arr):
	value_counts = defaultdict(int)
	for item in arr:
		value_counts[item] = value_counts[item] + 1
	return value_counts

def main():
	for i in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		e = 0
		o = 0
		m = 0
		for i in range(n):
			if a[i] % 2 == 0:
				e += 1
			else:
				o += 1
			if i % 2 != a[i] % 2:
				m += 1
		if n % 2 == 0:
			if o // 2 == e // 2:
				print(m // 2)
			else:
				print(-1)
		else:
			p = (n + 1) // 2
			if o + 1 == p and e == p:
				print(m // 2)
			else:
				print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	d = {}
	for i in range(n):
		if i % 2 != a[i] % 2:
			c += 1
			d[i] = a[i] % 2
	if c % 2 == 1:
		print(-1)
		continue
	if c == 0:
		print(0)
		continue
	even_num = 0
	odd_num = 0
	even_ind = 0
	odd_ind = 0
	for i in d:
		if a[i] % 2 == 0:
			even_num += 1
		else:
			odd_num += 1
		if i % 2 == 0:
			even_ind += 1
		else:
			odd_ind += 1
	if even_num == even_ind and odd_ind == odd_num:
		print(c // 2)
	else:
		print(-1)


T = int(input())
for q in range(T):
	N = int(input())
	L = list(map(int, input().split()))
	(Even, Odd) = (0, 0)
	(WrongEven, WrongOdd) = (0, 0)
	for i in range(len(L)):
		if L[i] % 2 == 0:
			Even += 1
		else:
			Odd += 1
		if L[i] % 2 == 0 and i % 2 != 0:
			WrongEven += 1
		if L[i] % 2 != 0 and i % 2 == 0:
			WrongOdd += 1
	if len(L) % 2 == 0 and Even == Odd:
		if WrongEven < WrongOdd:
			print(WrongEven)
		else:
			print(WrongOdd)
	elif len(L) % 2 == 1 and Even == Odd + 1:
		if WrongEven < WrongOdd:
			print(WrongEven)
		else:
			print(WrongOdd)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	p = 0
	r = -1
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				p += 1
		elif l[i] % 2 == 0:
			s += 1
	if s == p:
		r = s
	else:
		r = -1
	print(int(r))


for _ in range(int(input())):
	n = int(input())
	a = [int(a) for a in input().split()]
	p = [a for a in a if a % 2 == 0]
	q = [a for a in a if a % 2 != 0]
	if n == 1:
		if sum(a) % 2 == 0:
			print(0)
		else:
			print(-1)
	elif n % 2 == 0 and len(p) != n // 2:
		print(-1)
	elif n % 2 != 0 and len(q) != n // 2:
		print(-1)
	else:
		c = 0
		for i in range(n):
			if a[i] % 2 != i % 2:
				c = c + 1
		print(c // 2)


for _ in range(int(input())):
	n = int(input())
	a = input().split()
	bad_pos = 0
	even = 0
	for i in range(n):
		k = int(a[i]) % 2
		if k != i % 2:
			bad_pos += 1
		if k == 0:
			even += 1
	k = n % 2
	if even == n // 2 + k and n - even == n // 2:
		print(bad_pos // 2)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	for i in l:
		l1.append(i % 2)
	length = len(l1)
	if n % 2 == 0 and l1.count(0) != l1.count(1) or (n % 2 == 1 and l1.count(0) != l1.count(1) + 1):
		print('-1')
	else:
		temp = 0
		for i in range(0, length, 2):
			if l1[i] != 0:
				temp += 1
		for i in range(1, length, 2):
			if l1[i] != 1:
				temp += 1
		result = int(temp / 2)
		print(result)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	wo = 0
	we = 0
	for i in range(n):
		if i % 2 != a[i] % 2 and i % 2 == 0:
			we += 1
		elif i % 2 != a[i] % 2 and i % 2 == 1:
			wo += 1
	if wo != we:
		print('-1')
	else:
		print(wo)


from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
import math
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()
rli = lambda : map(int, stdin.readline().split())
rlf = lambda : map(float, stdin.readline().split())
(INF, NINF) = (float('inf'), float('-inf'))

def main():
	T = int(rl())
	for _ in range(T):
		n = int(rl())
		A = list(rli())
		(evenelems, oddelems) = (0, 0)
		(evenin, oddin) = (0, 0)
		(eo, oe) = (0, 0)
		for (i, a) in enumerate(A):
			if i % 2 == 0:
				evenin += 1
				if a % 2 == 1:
					eo += 1
			else:
				oddin += 1
				if a % 2 == 0:
					oe += 1
			if a % 2 == 0:
				evenelems += 1
			else:
				oddelems += 1
		ans = min(eo, oe)
		eo -= ans
		oe -= ans
		if eo == 0 and oe == 0:
			print(ans)
		else:
			print(-1)
	stdout.close()
main()


from math import *
from copy import *
from string import *
from random import *
from sys import stdin, stdout
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math
import math
import time
from queue import Queue

def seive(n):
	l = [True]
	l = l * (n + 1)
	for i in range(2, int(sqrt(n)) + 1):
		if l[i] == True:
			val = i * i
			while val < len(l):
				l[val] = False
				val += i
	prime = []
	for i in range(2, len(l)):
		if l[i] == True:
			prime.append(i)
	return prime

def dp(l, i, n, val, ans):
	if i >= n or val < 0:
		return 1000000
	elif val == 0:
		return 0
	else:
		if ans[i] == 1000000:
			ans[i] = min(min(1 + dp(l, i + 1, n, val - l[i], ans), 1 + dp(l, i, n, val - l[i], ans)), dp(l, i + 1, n, val, ans))
		return ans[i]
from queue import Queue

def factors(n):
	l = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def check1(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v -= 1

def check2(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v += 1
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	odd = 0
	even = 0
	for j in range(n):
		if j % 2 == 0:
			if l[j] % 2 == 0:
				continue
			else:
				even += 1
		elif l[j] % 2 != 0:
			continue
		else:
			odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = [*map(int, input().split())]
	(o, e, ans) = (0, 0, 0)
	for (i, x) in enumerate(arr):
		if i % 2 != x % 2:
			ans += 1
		o += x % 2 != 0 and x != 0
		e += x % 2 == 0
	print(-1 if ans % 2 or (n & 1 and o != (n + 1) // 2 - 1 or (n % 2 == 0 and o != n // 2)) else ans // 2)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
entries = inp()
for i in range(entries):
	z = inp()
	l = inlt()
	even = 0
	odd = 0
	even_error = 0
	odd_error = 0
	j = 0
	while j < len(l):
		if l[j] % 2 == 1:
			odd += 1
			if j % 2 == 0:
				odd_error += 1
		else:
			even += 1
			if j % 2 == 1:
				even_error += 1
		j += 1
	if odd_error != even_error:
		print(-1)
	else:
		print(odd_error)


n = int(input())
for i in range(n):
	t = int(input())
	c = list(map(int, input().split()))
	e = []
	f = []
	zeros0 = 0
	ones0 = 0
	zeros1 = 0
	ones1 = 0
	for j in range(t):
		e.append(j % 2)
		if j % 2 == 0:
			zeros0 = zeros0 + 1
		else:
			ones0 = ones0 + 1
		f.append(c[j] % 2)
		if c[j] % 2 == 0:
			zeros1 = zeros1 + 1
		else:
			ones1 = ones1 + 1
	count = 0
	for j in range(t):
		if e[j] == f[j]:
			pass
		else:
			count = count + 1
	if zeros0 == zeros1 and ones0 == ones1:
		print(int(count / 2))
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = []
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			c.append(i % 2)
	if c.count(1) == c.count(0):
		print(c.count(1))
	else:
		print(-1)


from sys import stdin, stdout
for test in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr1 = [int(x) for x in stdin.readline().split()]
	odd = n // 2
	even = n - odd
	co = 0
	ce = 0
	for i in arr1:
		if i % 2 == 0:
			ce += 1
		else:
			co += 1
	if co == odd and ce == even:
		count = 0
		for i in range(n):
			if i % 2 == 0 and arr1[i] % 2 == 0:
				count += 1
			elif i % 2 == 1 and arr1[i] % 2 == 1:
				count += 1
		count = n - count
		if count % 2 == 1:
			stdout.write('-1\n')
		else:
			stdout.write(str(count // 2) + '\n')
	else:
		stdout.write('-1\n')


from sys import stdin as lector
input = lector.readlines()
count = 1
for i in range(1, int(input[0]) + 1):
	larray = int(input[count])
	count += 1
	array = input[count].split(' ')
	count += 1
	array = list(map(int, array))
	res = -1
	if larray == 1:
		if array[0] % 2 == 0:
			res = 0
	else:
		pares = list(map(lambda x: x % 2 == 0, array))
		inpares = list(map(lambda x: 1 - x % 2 == 0, array))
		np = sum(pares)
		nimp = sum(inpares)
		indicesPares = list(range(0, larray, 2))
		indicesImPares = list(range(-1, larray, 2))
		indicesImPares.pop(0)
		if len(indicesPares) == np and len(indicesImPares) == nimp:
			if larray % 2 == 0:
				if np == nimp:
					par = list(map(lambda x: 1 - array[x] % 2 == 0, indicesPares))
					res = sum(par)
			elif abs(np - nimp) == 1:
				par = list(map(lambda x: 1 - array[x] % 2 == 0, indicesPares))
				res = sum(par)
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(a) for a in input().split()]
	cnt = 0
	cnt2 = 0
	for i in range(n):
		if A[i] % 2 == 1:
			cnt += 1
			if i % 2 == 1:
				cnt2 += 1
	if cnt == n // 2:
		ans = abs(cnt2 - n // 2)
	else:
		ans = -1
	print(ans)


q = int(input())
for i in range(1, q + 1):
	n = int(input())
	a = [int(x) for x in input().split()]
	odd = 0
	even = 0
	fine = 0
	for i in range(len(a)):
		if i % 2 == 0:
			if a[i] % 2 == 0:
				fine += 1
			else:
				even += 1
		elif a[i] % 2 == 1:
			fine += 1
		else:
			odd += 1
	if fine == n:
		print(0)
	elif odd == even:
		print(even)
	else:
		print('-1')


z = int(input())
while z:
	z -= 1
	n = int(input())
	a = list(map(int, input().split()))
	(od, ev) = (0, 0)
	(so, se) = (0, 0)
	for i in range(n):
		if i & 1:
			if not a[i] & 1:
				so += 1
		elif a[i] & 1:
			se += 1
	if se != so:
		print(-1)
		continue
	print(se)


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	oc = 0
	ec = 0
	for i in range(n):
		if i % 2 == 1 and i % 2 != arr[i] % 2:
			oc += 1
		if i % 2 == 0 and i % 2 != arr[i] % 2:
			ec += 1
	if oc == ec:
		print(oc)
	else:
		print(-1)
	t -= 1


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	for t in range(I()):
		n = I()
		arr = L()
		(ev, od) = (0, 0)
		for i in range(n):
			if i % 2 == 0:
				if arr[i] % 2 != 0:
					ev += 1
			elif arr[i] % 2 == 0:
				od += 1
		if ev == od:
			print(ev)
		else:
			print(-1)
main()


def d(a):
	return [i for i in range(len(a)) if a[i] % 2 != i % 2]

def b(a):
	return ([i for i in a if i % 2 == 0], [i for i in a if i % 2 != 0])

def c():
	input()
	(c, n) = b(d([int(i) for i in input().split()]))
	if len(c) == len(n):
		return len(c)
	else:
		return -1
[print(c()) for i in range(int(input()))]


def main():
	n = int(input())
	for _ in range(n):
		_ = int(input())
		arr = list((int(i) for i in input().strip().split()))
		print(is_good_array(arr))

def is_good_array(arr):
	(evens_mistaken, odds_mistaken) = (0, 0)
	for (idx, elem) in enumerate(arr):
		if idx % 2 == elem % 2:
			continue
		elif idx % 2 == 0:
			evens_mistaken += 1
		else:
			odds_mistaken += 1
	return evens_mistaken if evens_mistaken == odds_mistaken else -1
main()


from math import *
t = int(input())
for q in range(t):
	n = int(input())
	a = [int(f) for f in input().split()]
	cet = 0
	ncet = 0
	cetreq = ceil(n / 2)
	ncetreq = floor(n / 2)
	for i in range(n):
		if a[i] % 2 == 0:
			cet += 1
		else:
			ncet += 1
	if ncet != ncetreq or cet != cetreq:
		ans = -1
	else:
		ans = 0
		ch = 0
		for i in range(n):
			if a[i] % 2 != i % 2:
				ch += 1
		ans = ch // 2
	print(ans)


def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		A = list(map(int, input().split()))
		ans = 0
		(evenEle, oddEle) = (0, 0)
		for i in range(N):
			if A[i] % 2 == 0:
				evenEle += 1
			else:
				oddEle += 1
		if N % 2 == 0 and evenEle != oddEle or (N % 2 != 0 and evenEle != oddEle + 1):
			print(-1)
		else:
			(evenEle, oddEle) = (0, 0)
			for i in range(N):
				if A[i] % 2 != i % 2:
					if i % 2 == 0:
						oddEle += 1
					else:
						evenEle += 1
			print(min(evenEle, oddEle))
main()


from sys import stdout, stdin
input = stdin.readline
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	odd = []
	even = []
	ev = 0
	ans = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			ans = -1
		if a[i] % 2 == 1:
			ev += 1
		if a[i] % 2 == 0 and i % 2 == 1:
			even.append(i)
		elif a[i] % 2 == 1 and i % 2 == 0:
			odd.append(i)
	if ans == 0:
		print(ans)
		continue
	if ev != n // 2:
		print(-1)
		continue
	b = len(even)
	c = len(odd)
	if (b + c) % 2 == 0:
		print((b + c) // 2)
	else:
		print((b + c + 1) // 2)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	e = 0
	o = 0
	tp = 0
	for i in range(n):
		if s[i] % 2 != i % 2:
			tp += 1
			if s[i] & 1:
				o += 1
			else:
				e += 1
	if tp % 2 == 0 and o == e:
		print(tp // 2)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	L = list(map(int, input().split()))
	(e, o) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and L[i] % 2 == 1:
			o += 1
		if i % 2 == 1 and L[i] % 2 == 0:
			e += 1
	if not e == o:
		print(-1)
	else:
		print(o)


test_cases = int(input())
for _ in range(test_cases):
	input()
	a = list(map(int, input().split()))
	even_oop = 0
	odd_oop = 0
	for (i, ele) in enumerate(a):
		if i % 2 == 0 and ele % 2 == 1:
			even_oop += 1
		if i % 2 == 1 and ele % 2 == 0:
			odd_oop += 1
	if even_oop != odd_oop:
		print(-1)
	else:
		print(even_oop)


a = int(input())
for i in range(a):
	z = int(input())
	c = 0
	c1 = 0
	k = list(map(int, input().split()))
	for j in range(len(k)):
		if j % 2 == 0 and k[j] % 2 != 0:
			c += 1
		elif j % 2 != 0 and k[j] % 2 == 0:
			c1 += 1
	if c == c1:
		print(c)
	else:
		print(-1)


def fun(a, n):
	if n == 1:
		if a[0] % 2 == 0:
			return 0
		else:
			return -1
	ctEven = 0
	ctOdd = 0
	(e, o) = (0, 0)
	for i in range(n):
		if a[i] % 2 == 0:
			ctEven += 1
		if a[i] % 2 != 0:
			ctOdd += 1
		if i % 2 == 0 and a[i] % 2 != 0:
			e += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			o += 1
	if e != o:
		return -1
	else:
		return e
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = fun(a, n)
	print(ans)


t = int(input())
answers = []
for case in range(t):
	n = int(input())
	array = [int(i) for i in input().split()]
	even = 0
	odd = 0
	different = 0
	even_index = 0
	for i in range(n):
		if array[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if array[i] % 2 != i % 2:
			different += 1
		if i % 2 == 0:
			even_index += 1
	if even != even_index:
		answers.append(-1)
	else:
		answers.append(different // 2)
for answer in answers:
	print(answer)


num = int(input())
for cases in range(num):
	listLen = int(input())
	A = [int(x) for x in input().split()]
	h = {}
	h[0] = 0
	h[1] = 0
	num_odds = 0
	for i in range(len(A)):
		num_odds += A[i] % 2
		if i % 2 == 0 and A[i] % 2 == 1:
			h[i % 2] += 1
		if i % 2 == 1 and A[i] % 2 == 0:
			h[i % 2] += 1
	if num_odds != len(A) // 2:
		print(-1)
		continue
	print(h[0])


import sys

def solve(a):
	(nz, no) = (0, 0)
	for i in range(len(a)):
		if not a[i] % 2 == i % 2:
			if i % 2 == 0:
				no += 1
			else:
				nz += 1
	return nz if nz == no else -1
IN = [x.strip() for x in sys.stdin.readlines()]
T = int(IN[0])
cur = 1
for ti in range(T):
	l = int(IN[cur])
	a = [int(x) for x in IN[cur + 1].split(' ')]
	result = solve(a)
	print(result)
	cur += 2


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	odd_m = 0
	even_m = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 == 1:
			even_m += 1
		if i % 2 == 1 and arr[i] % 2 == 0:
			odd_m += 1
	if odd_m != even_m:
		print(-1)
	else:
		print(odd_m)


from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		n = int(input())
		l = [int(i) for i in input().split(' ')]
		c = 0
		m = []
		p = []
		for i in range(n):
			if i % 2 != l[i] % 2:
				m.append(i % 2)
				p.append(l[i] % 2)
		if len(m) % 2 == 0 and m.count(0) == p.count(0) and (m.count(1) == p.count(1)):
			print(len(m) // 2)
		else:
			print(-1)
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m_one = 0
	m_two = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2:
				m_one += 1
			else:
				m_two += 1
	if m_one + m_two == 0:
		print(0)
	elif m_one == m_two:
		print(m_one)
	else:
		print(-1)


def driver():
	t = int(input())
	for i in range(t):
		solution()

def solution():
	n = int(input())
	a = [int(x) for x in input().split()]
	oe = 0
	o = 0
	e = 0
	for i in range(n):
		if i % 2 == a[i] % 2:
			continue
		else:
			oe += 1
			if a[i] % 2 == 0:
				e += 1
			else:
				o += 1
	if oe == 0:
		print(0)
		return
	elif o != e:
		print(-1)
		return
	else:
		print(oe // 2)
driver()


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	n = ii()
	a = li()
	(odd, even) = (0, 0)
	for i in range(n):
		if i & 1 and a[i] % 2 == 0:
			even += 1
		elif i % 2 == 0 and a[i] & 1:
			odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


def main(xs):
	odd = sum((x % 2 for x in xs))
	even = len(xs) - odd
	if odd != even and odd + 1 != even:
		return -1
	else:
		return sum((x % 2 and (x - i) % 2 for (i, x) in enumerate(xs)))
n = int(input())
for _ in range(n):
	input()
	print(main(list(map(int, input().split()))))


for s in [*open(0)][2::2]:
	(even, odd) = ([], [])
	for (i, j) in enumerate(map(int, s.split())):
		if i % 2 == 0 and j % 2 != 0:
			even.append(j)
		elif i % 2 != 0 and j % 2 == 0:
			odd.append(j)
	if len(even) == len(odd):
		print(len(even))
	else:
		print(-1)


for i in range(int(input())):
	num = int(input())
	array = list(map(int, input().split()))
	evenIndexCount = 0
	evenNumCount = 0
	for j in range(len(array)):
		if j % 2 != array[j] % 2:
			if j % 2 == 0:
				evenIndexCount += 1
			if array[j] % 2 == 0:
				evenNumCount += 1
	if evenIndexCount == evenNumCount:
		print(evenIndexCount)
	else:
		print(-1)


t = int(input())
ans = list()
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	check = list()
	new = list()
	for j in range(n):
		if arr[j] % 2 == 0:
			new.append(0)
		else:
			new.append(1)
		if j % 2 == 0:
			check.append(0)
		else:
			check.append(1)
	if new == check:
		ans.append(0)
	else:
		zero_n = 0
		one_n = 0
		zero_c = 0
		one_c = 0
		diff = 0
		for k in range(n):
			if new[k] == 0:
				zero_n = zero_n + 1
			else:
				one_n = one_n + 1
			if check[k] == 0:
				zero_c = zero_c + 1
			else:
				one_c = one_c + 1
		if zero_c == zero_n and one_c == one_n:
			for k in range(n):
				if new[k] != check[k]:
					diff = diff + 1
			if diff % 2 == 0:
				ans.append(diff / 2)
			else:
				ans.append(-1)
		else:
			ans.append(-1)
for i in range(t):
	print(int(ans[i]))


t = int(input())
lenLst = []
arrLst = []
for tt in range(t):
	length_i = int(input())
	lenLst.append(length_i)
	elem = []
	elem = input().split()
	for e in range(len(elem)):
		elem[e] = int(elem[e])
	arrLst.append(elem)
for i in range(t):
	(nE, nO) = (0, 0)
	for j in range(lenLst[i]):
		if arrLst[i][j] % 2 == 0:
			nE += 1
		else:
			nO += 1
	if lenLst[i] > 1:
		if lenLst[i] % 2 == 0:
			if nE != nO:
				print(-1)
				continue
			else:
				count = 0
				for j in range(lenLst[i]):
					if j % 2 != arrLst[i][j] % 2:
						count += 1
				moves = count // 2
				print(moves)
				continue
		elif nE - nO != 1:
			print(-1)
			continue
		else:
			count = 0
			for j in range(lenLst[i]):
				if j % 2 != arrLst[i][j] % 2:
					count += 1
			moves = count // 2
			print(moves)
			continue
	elif arrLst[i][0] % 2 == 0:
		print(0)
	else:
		print(-1)


tc = int(input())
for _ in range(tc):
	n = int(input())
	a = [int(x) for x in input().split()]
	(e, o) = (0, 0)
	for (i, neg) in enumerate(a):
		if i % 2 is not neg % 2:
			if i % 2 == 0:
				e += 1
			else:
				o += 1
	if o == e:
		print(o)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	v = 0
	for i in range(len(l)):
		if i % 2 == 0 and l[i] % 2 != 0:
			c = c + 1
		elif i % 2 != 0 and l[i] % 2 == 0:
			v = v + 1
	if c == v:
		print(c)
	else:
		print('-1')


for _ in range(int(input())):
	p = 0
	n = 0
	q = int(input())
	arr = list(map(int, input().split()))
	for i in range(1, q, 2):
		if arr[i] % 2 != 1:
			p += 1
	for j in range(0, q, 2):
		if arr[j] % 2 != 0:
			n += 1
	if p != n:
		print(-1)
	else:
		print(p)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	inv = 0
	odd = 0
	even = 0
	for j in range(len(arr)):
		if j % 2 != arr[j] % 2:
			inv += 1
			if j % 2 == 0:
				even += 1
			else:
				odd += 1
	print(even if odd == even else -1)


def evenarr(n, a):
	even = 0
	odd = 0
	for i in range(len(a)):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 0:
				odd += 1
			else:
				even += 1
	if even == odd:
		return even
	else:
		return -1
test = int(input())
for i in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	print(evenarr(n, a))


t = int(input())
for i in range(t):
	n = int(input())
	nums = list(map(int, input().rstrip().split()))
	count = 0
	(even, odd) = (0, 0)
	for i in range(len(nums)):
		if i % 2 != nums[i] % 2:
			if i % 2 == 1:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


import sys
import os
import heapq
import math
try:
	path = './file/input.txt'
	if os.path.exists(path):
		sys.stdin = open(path, 'r')
except:
	pass
t = int(input())

def printd(value):
	pass

def case():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	num = 0
	result = 0
	for (index, value) in enumerate(arr):
		num += 1 if value % 2 == 0 else -1
		if index % 2 == 0 and value % 2 != 0:
			result += 1
	print(result if num == 0 or num == 1 else -1)
for _ in range(t):
	case()


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	if n == 1:
		if arr[0] & 1:
			print(-1)
		else:
			print(0)
	else:
		moves = 0
		for i in range(n):
			if i % 2 != arr[i] % 2:
				moves += 1
		if moves == 0:
			print(0)
			continue
		odd = 0
		eve = 0
		for i in arr:
			if i & 1:
				odd += 1
			else:
				eve += 1
		if n % 2 == 0:
			if odd != eve:
				print(-1)
				continue
		elif odd >= eve:
			print(-1)
			continue
		evea = 0
		odda = 0
		for i in range(n):
			if i % 2 != arr[i] % 2 and arr[i] & 1:
				odda += 1
			if i % 2 != arr[i] % 2 and arr[i] % 2 == 0:
				evea += 1
		if odda == evea:
			print(odda)
		else:
			print(-1)


n = int(input())
for _ in range(n):
	d = int(input())
	ff = list(map(int, input().split(' ')))
	chet = []
	ne_chet = []
	cv = [''] * len(ff)
	cvb = []
	c = 0
	for (idx, i) in enumerate(ff):
		if idx % 2 == 0:
			if i % 2 == 0:
				cvb.append(i)
			else:
				cvb.append('')
				ne_chet.append(i)
		elif i % 2 != 0:
			cvb.append(i)
		else:
			cvb.append('')
			chet.append(i)
	chet = chet[::-1]
	ne_chet = ne_chet[::-1]
	for (idx, i) in enumerate(cvb):
		if idx % 2 == 0:
			if i == '':
				if len(chet) != 0:
					cvb[idx] = chet.pop()
					c += 1
				else:
					print(-1)
					break
		elif i == '':
			if len(ne_chet) != 0:
				cvb[idx] = ne_chet.pop()
				c += 1
			else:
				print(-1)
				break
	else:
		print(int(c // 2))


for _ in range(int(input())):
	n = int(input())
	z = list(map(int, input().split()))
	even = []
	eveno = []
	odd = []
	oddno = []
	for i in range(n):
		if i % 2 == 0 and z[i] % 2 == 0:
			even.append(i)
		elif i % 2 == 0:
			eveno.append(i)
		elif i % 2 != 0 and z[i] % 2 != 0:
			odd.append(i)
		elif i % 2 != 0:
			oddno.append(i)
	if len(eveno) == len(oddno):
		print(len(eveno))
	else:
		print(-1)


t = int(input())
for t in range(0, t):
	n = int(input())
	a = [int(x) for x in input().split()]
	x = 0
	y = 0
	for i in range(0, n, 2):
		if a[i] % 2 != 0:
			x = x + 1
	for j in range(1, n, 2):
		if a[j] % 2 == 0:
			y = y + 1
	if x == 0 and y == 0:
		print(0)
	elif x != y:
		print(-1)
	elif x == y:
		print(x)
	else:
		print(abs(x - y))


import sys
input = iter(sys.stdin.read().splitlines()).__next__
sys.setrecursionlimit(10000)
TC = int(input())
for tc in range(TC):
	N = int(input())
	A = list(map(int, input().split()))
	mismatches = [0, 0]
	for i in range(N):
		if i & 1 != A[i] & 1:
			mismatches[i & 1] += 1
	res = mismatches[0] if mismatches[0] == mismatches[1] else -1
	print(res)


L1 = []
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	num = 0
	for i in a:
		b.append(i % 2)
	for i in range(n):
		if i % 2 != b[i] % 2:
			num += 1
	ans = num // 2
	c = []
	for i in range(n):
		c.append(i % 2)
	if sorted(c) != sorted(b):
		ans = -1
	if b.count(1) + b.count(0) != len(b) or (len(b) == 1 and b[0] % 2 != 0) or (len(b) != 1 and len(set(b)) == 1):
		ans = -1
	L1.append(ans)
for i in L1:
	print(i)


T = int(input())

def solve(array):
	count1 = 0
	count2 = 0
	for i in range(len(array)):
		if i % 2 != array[i] % 2:
			if i % 2 != 0:
				count1 += 1
			else:
				count2 += 1
	if count1 != count2:
		return -1
	else:
		return count1
out_li = []
for _ in range(T):
	n = int(input())
	array = list(map(int, input().split()))
	out_li.append(solve(array))
for num in out_li:
	print(num)


def good(l, n):
	(c1, c2) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 == 1:
			c1 += 1
		elif i % 2 == 1 and l[i] % 2 == 0:
			c2 += 1
	if c1 == c2:
		return c1
	return -1
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(good(l, n))


t = int(input())
while t > 0:
	n = int(input())
	li = list(map(int, input().split(' ')))
	if n % 2 == 0:
		li2 = [0, 1] * (n // 2)
	else:
		li2 = [0, 1] * (n // 2) + [0]
	res = 0
	res2 = 0
	k = 0
	for (a, b) in zip(li, li2):
		if a % 2 != b:
			if k % 2 == 0:
				res += 1
			else:
				res2 += 1
		k += 1
	if res == res2:
		print(res)
	else:
		print(-1)
	t -= 1


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	j = 0
	even = 0
	odd = 0
	switch = 0
	while j < n:
		if switch == 0:
			if l[j] % 2 != 0:
				odd = odd + 1
			switch = 1
		else:
			if l[j] % 2 == 0:
				even = even + 1
			switch = 0
		j = j + 1
	if odd == even:
		print(odd)
	else:
		print(-1)


a = []
b = []
for i in range(int(input())):
	n = int(input())
	a = input().split(maxsplit=n)
	a = [int(item) for item in a]
	s = 0
	p = 0
	for i in range(n):
		if a[i] % 2 == 1 and i % 2 == 0:
			s = s + 1
		elif a[i] % 2 == 0 and i % 2 == 1:
			p = p + 1
	if p != s:
		b.append(-1)
	else:
		b.append(s)
	a.clear()
print(*b, sep='\n')


import sys
I = sys.stdin.readline
for _ in range(int(I())):
	n = int(I())
	arr = list(map(int, I().split()))
	o = 0
	e = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			o += 1
		elif i % 2 == 1 and arr[i] % 2 == 0:
			e += 1
	if o != e:
		print(-1)
	else:
		print(o)


for _ in range(int(input())):
	no = int(input())
	arr = list(map(int, input().split()))
	count_odd = 0
	count_even = 0
	for i in range(no):
		if i & 1 == 1:
			if arr[i] & 1 == 1:
				pass
			else:
				count_even = count_even + 1
		elif arr[i] & 1 == 1:
			count_odd = count_odd + 1
		else:
			pass
	if no & 1 == 0:
		if count_odd == count_even:
			print(count_even)
		else:
			print(-1)
	elif count_odd == count_even:
		print(count_even)
	else:
		print(-1)


n = int(input())
for j in range(n):
	m = int(input())
	my_list = list(map(int, input().split()))
	mis_odd = 0
	mis_even = 0
	for i in range(m):
		if i % 2 == 0 and my_list[i] % 2 == 1:
			mis_even += 1
		if i % 2 == 1 and my_list[i] % 2 == 0:
			mis_odd += 1
	if mis_odd == mis_even == 0:
		print(0)
	elif mis_odd != mis_even:
		print(-1)
	else:
		print(mis_even)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	e = 0
	if n % 2 == 0:
		f = n // 2
	else:
		f = n // 2 + 1
	for i in l:
		if i % 2 == 0:
			e += 1
	if f != e:
		print('-1')
	else:
		c = 0
		e = 0
		for i in range(n):
			if l[i] % 2 != i % 2:
				if i % 2 == 0:
					e += 1
		print(e)


import math
t = int(input())
for _ in range(0, t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	init = [i % 2 for i in range(0, n)]
	count = 0
	noans = True
	(icount0, icount1) = (0, 0)
	for i in range(0, n):
		if init[i] == 0:
			icount0 += 1
		else:
			icount1 += 1
	for i in range(0, n):
		if arr[i] % 2 != init[i]:
			count += 1
	init2 = [i % 2 for i in arr]
	(acount0, acount1) = (0, 0)
	for i in range(0, n):
		if init2[i] == 0:
			acount0 += 1
		else:
			acount1 += 1
	if acount0 != icount0 or acount1 != icount1:
		noans = False
	elif acount0 == icount0 or acount1 == icount1:
		noans = True
	if noans:
		print(count // 2)
	else:
		print('-1')


def solve(n, arr):
	if n == 1 and arr[0] % 2 != 0:
		return -1
	elif n == 1 and arr[0] % 2 == 0:
		return 0
	oddi = 1
	eveni = 0
	c = 0
	while True:
		while eveni < n and arr[eveni] % 2 == 0:
			eveni += 2
		while oddi < n and arr[oddi] % 2 == 1:
			oddi += 2
		if oddi < n and eveni < n:
			(arr[oddi], arr[eveni]) = (arr[eveni], arr[oddi])
			c += 1
		else:
			break
	flag = 0
	for i in range(len(arr)):
		if arr[i] % 2 != i % 2:
			flag = 1
			break
	if flag == 0:
		return c
	else:
		return -1
try:
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		print(solve(n, arr))
except EOFError:
	pass


p = int(input())
while p:
	n = int(input())
	a = list(map(int, input().strip().split()))
	(e, o) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			e += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			o += 1
	if o == e:
		print(e)
	else:
		print(-1)
	p -= 1


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split(' ')))
	final = []
	cal = []
	count = 0
	for j in range(len(array)):
		final.append(array[j] % 2)
	if n % 2 == 0:
		for k in range(n // 2):
			cal.append(0)
			cal.append(1)
	else:
		for a in range(n // 2 + 1):
			cal.append(0)
			cal.append(1)
	if n % 2 != 0:
		cal.pop()
	count0 = cal.count(0)
	count1 = cal.count(1)
	fcount0 = final.count(0)
	fcount1 = final.count(1)
	if count0 != fcount0 and count1 != fcount1:
		print(-1)
	else:
		for m in range(len(final)):
			if final[m] != cal[m]:
				count += 1
		if count % 2 == 0:
			print(count // 2)
		else:
			print(count)


a = int(input())
for i in range(a):
	b = int(input())
	count1 = 0
	count2 = 0
	odd = 0
	even = 0
	c = list(map(int, input().split()))
	for g in range(b):
		if c[g] % 2 == 0:
			even += 1
		else:
			odd += 1
	if b % 2 == 0:
		if odd == even:
			for j in range(b):
				if j % 2 == 0 and c[j] % 2 == 0 or (j % 2 != 0 and c[j] % 2 != 0):
					count1 += 1
				else:
					count2 += 1
			if count1 == b:
				print(0)
			else:
				print(count2 // 2)
		else:
			print(-1)
	elif even - 1 == odd:
		for j in range(b):
			if j % 2 == 0 and c[j] % 2 == 0 or (j % 2 != 0 and c[j] % 2 != 0):
				count1 += 1
			else:
				count2 += 1
		if count1 == b:
			print(0)
		else:
			print(count2 // 2)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = map(int, input().rstrip().split(' '))
	l = [i % 2 for i in l]
	oatz = 0
	zato = 0
	correct = 0
	for i in range(n):
		if i % 2 != l[i]:
			if i % 2 and (not l[i]):
				zato += 1
			else:
				oatz += 1
		else:
			correct += 1
	if zato != oatz:
		print(-1)
	elif correct + 2 * zato != n:
		print(-1)
	else:
		print(zato)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x0 = 0
	x1 = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				x0 += 1
			else:
				x1 += 1
	if x0 == x1:
		print(x0)
	else:
		print(-1)


import sys
try:
	sys.stdin = open('inputs.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
finally:
	input = sys.stdin.readline
	print = sys.stdout.write
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	wrong_even = 0
	wrong_odd = 0
	for (ind, num) in enumerate(a):
		if ind & 1:
			if num & 1:
				pass
			else:
				wrong_odd += 1
		elif num & 1:
			wrong_even += 1
	if wrong_even == wrong_odd:
		print(str(wrong_odd))
		print('\n')
	else:
		print('-1\n')


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(n, a):
	cnt01 = sum([1 for i in range(n) if a[i] % 2 == 0 and i % 2 == 1])
	cnt10 = sum([1 for i in range(n) if a[i] % 2 == 1 and i % 2 == 0])
	return cnt01 if cnt01 == cnt10 else -1

def main():
	for _ in range(ri()):
		n = ri()
		a = ria()
		wi(solve(n, a))
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(v) for v in input().split()]
	o = 0
	e = 0
	for j in range(n):
		if j % 2 == 0:
			if a[j] % 2 != 0:
				e = e + 1
		elif a[j] % 2 == 0:
			o = o + 1
	if o == e:
		print(o)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	indexarray = [i % 2 for i in range(len(a))]
	elearray = [i % 2 for i in a]
	result = []
	for i in range(len(a)):
		result.append(abs(indexarray[i] - elearray[i]))
	even = 0
	odd = 0
	for i in range(len(result)):
		if i % 2 == 0 and result[i] != 0:
			even += 1
		elif i % 2 != 0 and result[i] != 0:
			odd += 1
	result = list(filter(lambda x: x != 0, result))
	if len(result) % 2 == 0 and odd == even:
		print(sum(result) // 2)
	else:
		print(-1)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, a):
	mismatch_even = 0
	mismatch_odd = 0
	for (i, item) in enumerate(a):
		if i % 2 != item % 2:
			if i % 2 == 0:
				mismatch_even += 1
			else:
				mismatch_odd += 1
	return mismatch_even if mismatch_odd == mismatch_even else -1
for i in tests():
	n = int_in()
	a = arr_in()
	out(solve(n, a))


def solve():
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	no0 = int(n / 2 + n % 2)
	no1 = int(n / 2)
	count0 = 0
	count1 = 0
	for i in a:
		if i % 2 == 0:
			count0 += 1
		else:
			count1 += 1
	if not (no0 == count0 and no1 == count1):
		print('-1')
		return
	count = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			count += 1
	if count % 2 == 0:
		print(int(count / 2))
	else:
		print('-1')
t = int(input())
for i in range(t):
	solve()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	d = 0
	a = []
	b = []
	for i in range(n):
		a.append(l[i] % 2)
		b.append(i % 2)
	for i in range(len(a)):
		if a[i] == 0 and b[i] == 1:
			c = c + 1
		if a[i] == 1 and b[i] == 0:
			d = d + 1
	if c == d:
		print(c)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	counte = 0
	counto = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			counte += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			counto += 1
	if counte == counto:
		print(counte)
	else:
		print(-1)


def count01(arr):
	zero = 0
	one = 0
	for i in arr:
		if i == 0:
			zero += 1
		else:
			one += 1
	return (zero, one)

def evenArray(n, arr):
	i = 0
	li1 = []
	while i < n:
		if i % 2 == 0:
			li1.append(0)
		else:
			li1.append(1)
		i += 1
	li2 = []
	i = 0
	for i in arr:
		li2.append(i % 2)
	(li1_zero, li1_one) = count01(li1)
	(li2_zero, li2_one) = count01(li2)
	if li1_zero == li2_zero and li1_one == li2_one:
		count = 0
		i = 0
		while i < n:
			if i % 2 == 0:
				if li2[i] != 0:
					for j in range(i + 1, n):
						if li2[j] == 0:
							if j % 2 != 0:
								count += 1
								swap = li2[j]
								li2[j] = li2[i]
								li2[i] = swap
								break
			elif li2[i] != 1:
				for j in range(i + 1, n):
					if li2[j] == 1:
						if j % 2 != 1:
							count += 1
							swap = li2[j]
							li2[j] = li2[i]
							li2[i] = swap
							break
			i += 1
		return count
	else:
		return -1
for _ in range(int(input())):
	n = int(input())
	li = [int(x) for x in input().split()]
	print(evenArray(n, li))


def even(n):
	return n % 2 == 0

def sol(l):
	c = 0
	e_idx = 0
	o_idx = 0
	e_n = 0
	o_n = 0
	for i in range(len(l)):
		if even(i) != even(l[i]):
			c += 1
			if even(i):
				e_idx += 1
			else:
				o_idx += 1
			if even(l[i]):
				e_n += 1
			else:
				o_n += 1
	if even(c):
		if e_n == e_idx and o_n == o_idx:
			return c // 2
		else:
			return -1
	else:
		return -1
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(sol(l))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	oc = 0
	ev = 0
	for i in range(n):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				oc += 1
		elif l[i] % 2 == 0:
			ev += 1
	if ev != oc:
		print(-1)
	else:
		print((ev + oc) // 2)


for testcase in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	even = 0
	odd = 0
	for (i, val) in enumerate(arr):
		if i % 2 != val % 2:
			if val & 1:
				odd += 1
			else:
				even += 1
	if odd != even:
		print(-1)
	else:
		print(odd)


cases = int(input())
for t in range(cases):
	n = int(input())
	a = list(map(int, input().split()))
	(even, odd) = (0, 0)
	for (i, v) in enumerate(a):
		if i % 2 != v % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	indexes = list()
	al = [-1] * n
	ans = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			indexes.append(i)
		else:
			al[i] = a[i]
	for i in range(len(indexes)):
		for j in range(n):
			if a[indexes[i]] % 2 == j % 2 and al[j] == -1:
				al[j] = a[indexes[i]]
				ans += 1
				break
	if ans == len(indexes):
		print(int(ans / 2))
	else:
		print(-1)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	n = val()
	a = li()
	ans = evens = odds = 0
	for i in range(n):
		if a[i] & 1 == i & 1:
			continue
		elif a[i] & 1:
			odds += 1
		else:
			evens += 1
	if evens != odds:
		print(-1)
	else:
		print(evens)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even = sum((x % 2 == 0 for x in a))
	odd = sum((x % 2 == 1 for x in a))
	if even < (n + 1) // 2 or odd < n // 2:
		print(-1)
		continue
	change_even = 0
	change_odd = 0
	for (i, x) in enumerate(a):
		if i % 2 != x % 2:
			if i % 2:
				change_even += 1
			else:
				change_odd += 1
	print(max(change_even, change_odd))


from sys import stdin, stdout
import sys
from math import *
for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(n):
		if ar[i] % 2 != i % 2 and i % 2 == 0:
			e += 1
		elif ar[i] % 2 != i % 2 and i % 2 == 1:
			o += 1
	if e == o:
		print(e)
	else:
		print(-1)


n = int(input())
for j in range(0, n):
	l = int(input())
	a = list(map(int, input().split()))
	a1 = b1 = 0
	for i in range(0, l):
		if i % 2 == 0 and a[i] % 2 != 0:
			a1 += 1
		elif i % 2 == 1 and a[i] % 2 != 1:
			b1 += 1
	if a1 == b1:
		print(a1)
	elif a1 != b1:
		print(-1)
	else:
		print(0)


def inpi():
	return int(input())

def inps():
	return str(input())

def inparr():
	return list(map(int, input().split()))
for _ in range(inpi()):
	n = inpi()
	a = inparr()
	flag = False
	if n % 2 == 0:
		flag = True
	c = 0
	right = 0
	for i in range(n):
		if a[i] % 2 == 0:
			if i % 2 == 0:
				right += 1
			c += 1
	odd = n - c
	if flag:
		if odd == c:
			print(c - right)
		else:
			print(-1)
	elif odd == c - 1:
		print(c - right)
	else:
		print(-1)


t = int(input())
while t > 0:
	sum = 0
	count = 0
	a = int(input())
	l = list(map(int, input().split()))
	for i in range(0, len(l), 1):
		if i % 2 == 0:
			if l[i] % 2 == 1:
				sum += 1
		elif l[i] % 2 == 0:
			count += 1
	if sum == count:
		print(sum)
	else:
		print('-1')
	t -= 1


for t in range(int(input())):
	num = int(input())
	arr = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(num):
		if i % 2 == 0 and arr[i] % 2 != 0:
			o += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			e += 1
	if e == o:
		print(e)
	else:
		print(-1)


import math
from sys import stdin
from collections import Counter, defaultdict, deque
input = stdin.readline
mod = pow(10, 9) + 7

def solve():
	n = int(input())
	l1 = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(n):
		if l1[i] % 2 != i % 2 and i % 2 == 1:
			odd += 1
		elif l1[i] % 2 != i % 2 and i % 2 == 0:
			even += 1
	if odd != even:
		print(-1)
	else:
		print(odd)
for _ in range(int(input())):
	solve()


T = int(input())
while T:
	n = int(input())
	A = list(map(int, input().split()))
	o = 0
	e = 0
	for i in range(n):
		if A[i] % 2 != i % 2:
			if A[i] % 2 == 0:
				e = e + 1
			else:
				o = o + 1
	if o != e:
		print(-1)
	else:
		print(o)
	T = T - 1


t = int(input())
for i in range(t):
	n = int(input())
	even = odd = e = o = le = 0
	l = list(map(int, input().split(' ')))
	if n % 2 == 0:
		even = odd = n / 2
	else:
		odd = (n - 1) / 2
		even = odd + 1
	for j in l:
		if j % 2 == 0:
			e = e + 1
		else:
			o = o + 1
	if e != even or o != odd:
		print(-1)
	else:
		for j in range(0, n, 2):
			if l[j] % 2 == 0:
				le = le + 1
		print(e - le)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def foo():
	n = inp()
	lst = inlt()
	ans = odd = even = x = y = 0
	if n % 2 == 0:
		even = odd = n // 2
	else:
		odd = n // 2
		even = odd + 1
	for ele in lst:
		if ele % 2 == 0:
			x += 1
		else:
			y += 1
	if even != x or odd != y:
		print(-1)
		return
	for i in range(n):
		if i % 2 == 0 and lst[i] % 2 == 0:
			continue
		elif i % 2 != 0 and lst[i] % 2 != 0:
			continue
		else:
			ans += 1
	print(ans // 2)
t = inp()
for i in range(t):
	foo()


t = int(input())
r = []
for x in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	count1 = 0
	count2 = 0
	for i in range(len(a)):
		if a[i] % 2 == 0 and i % 2 == 1:
			count2 += 1
		elif a[i] % 2 == 1 and i % 2 == 0:
			count1 += 1
		else:
			pass
	if count1 != count2:
		r.append(-1)
	else:
		r.append(count1)
for x in r:
	print(x)


for lo in range(int(input())):
	n = int(input())
	ls = [int(x) for x in input().split()]
	c1 = c2 = 0
	for i in range(n):
		if i % 2 == 0:
			if ls[i] % 2 != 0:
				c1 += 1
		elif ls[i] % 2 == 0:
			c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)


T = int(input())
for t in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	required_odd = N // 2
	cur_odd = 0
	cur_placed_odd = 0
	for (i, ai) in enumerate(A):
		if ai % 2 == 1:
			cur_odd += 1
			if i % 2 == 1:
				cur_placed_odd += 1
	if cur_odd != required_odd:
		print(-1)
	else:
		print(abs(cur_odd - cur_placed_odd))


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = input()
	A = list(map(int, list(a.split())))
	B = [0] * n
	for i in range(n):
		B[i] = A[i] % 2 - i % 2
	if sum(B) != 0:
		print(-1)
	else:
		c = 0
		for i in range(n):
			if B[i] == 1:
				c = c + 1
		print(c)


import sys
import os
readline = sys.stdin.readline
inp = os.read(0, int(10000000.0)).split()
inp_pos = -1

def cin():
	global inp_pos
	inp_pos += 1
	return inp[inp_pos]
t = int(cin())
while t:
	odd = 0
	even = 0
	t -= 1
	n = int(cin())
	for i in range(n):
		a = int(cin())
		if a % 2 == 0 and i % 2 == 1:
			even += 1
		elif a % 2 == 1 and i % 2 == 0:
			odd += 1
	if even != odd:
		print(-1)
	else:
		print(even)


import math
import sys
from sys import *
import heapq
from collections import deque, defaultdict
from itertools import permutations, combinations, combinations_with_replacement
import random
import os
mod = 10 ** 9 + 7
MAX = sys.maxsize
MIN = -sys.maxsize - 1

def isPrime(n):
	if n > 1:
		for i in range(2, n):
			if n % i == 0:
				return False
		else:
			return True
	else:
		return False

def isPanagram(s):
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	for char in alphabet:
		if char not in s.lower():
			return False
	return True

def power2(n):
	return n and (not n & n - 1)

def diff(list1):
	res = [list1[i + 1] - list1[i] for i in range(len(list1) - 1)]
	return res

def isEqual(list1):
	if len(list1) < 0:
		res = True
	res = all((ele == list1[0] for ele in list1))
	if res:
		return True
	else:
		return False

def checkPali(s):
	ar = [0] * 256
	for i in range(len(s)):
		ar[ord(s[i])] = ar[ord(s[i])] + 1
	odd = 0
	for i in range(256):
		if ar[i] & 1:
			odd += 1
		if odd > 1:
			return False
	return True

def remove_duplicate(list1):
	final_list = list(set(list1))
	return final_list

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	(even, odd) = (0, 0)
	for i in range(n):
		if i % 2 != a[i] % 2:
			if a[i] % 2 == 0:
				even += 1
			else:
				odd += 1
	if odd != even:
		return -1
	else:
		return even
t = int(stdin.readline().strip())
for i in range(t):
	result = solve()
	stdout.write(str(result) + '\n')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ceven = 0
	for i in range(n):
		if a[i] % 2 == 0:
			ceven += 1
	codd = n - ceven
	if codd != n // 2:
		print(-1)
		continue
	else:
		peven = 0
		podd = 0
		for i in range(n):
			if i % 2 == 0 and a[i] % 2 == 1:
				podd += 1
			if i % 2 == 1 and a[i] % 2 == 0:
				peven += 1
		if peven == podd:
			print(peven)
		else:
			print(-1)


from collections import Counter
for _ in range(int(input())):
	_ = input()
	numeros = [int(x) for x in input().split()]

	def check(lista):
		res = []
		for (i, n) in enumerate(lista):
			if i % 2 != n % 2:
				res.append(n % 2)
		return res
	lista = check(numeros)
	if len(lista) == 0:
		print(0)
	else:
		contador = Counter(lista)
		if len(contador) < 2:
			print(-1)
		elif contador[0] == contador[1]:
			print(contador[0])
		else:
			print(-1)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	ans = 0
	a = 0
	f = 0
	if n == 1 and A[0] % 2 != 0:
		print('-1')
		continue
	for i in range(n):
		a = -1
		if i % 2 != 0 and A[i] % 2 == 0:
			for j in range(0, n):
				if j % 2 == 0 and A[j] % 2 != 0:
					a = 1
					ans += 1
					(A[i], A[j]) = (A[j], A[i])
					break
			if a == -1:
				f = 1
				print('-1')
				break
		elif i % 2 == 0 and A[i] % 2 != 0:
			for j in range(0, n):
				if j % 2 != 0 and A[j] % 2 == 0:
					a = 1
					ans += 1
					(A[i], A[j]) = (A[j], A[i])
					break
			if a == -1:
				f = 1
				print('-1')
				break
	if f == 1:
		continue
	print(ans)


import sys
input = sys.stdin.buffer.readline

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	n = int(input())
	arr = I()
	evenbads = 0
	oddbads = 0
	for i in range(n):
		if arr[i] % 2 != i % 2:
			if arr[i] % 2:
				oddbads += 1
			else:
				evenbads += 1
	if evenbads != oddbads:
		print(-1)
	else:
		print(evenbads)


def even(l, n):
	p = 0
	q = 0
	flag = 0
	for i in range(n):
		if flag == 0:
			if l[i] % 2 != 0:
				p += 1
			flag = 1
		else:
			if l[i] % 2 == 0:
				q += 1
			flag = 0
	if p == q:
		return p
	else:
		return -1
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(even(l, n))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(e, o) = (0, 0)
	f = []
	for i in l:
		if i % 2 == 0:
			e += 1
			f.append(0)
		else:
			o += 1
			f.append(1)
	if e != o and n % 2 == 0 or (e != o + 1 and n % 2 == 1) or (n == 1 and e != 1):
		print(-1)
		continue
	r = 0
	for i in range(n):
		if f[i] == 0 and i % 2 != 0 or (f[i] == 1 and i % 2 != 1):
			r += 1
	print(r // 2)


import sys
for i in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	li = list(map(int, sys.stdin.readline().split()))
	for j in range(n):
		li[j] = li[j] % 2
	one = sum(li)
	if one != n // 2:
		print(-1)
		continue
	cnt = 0
	for i in range(n):
		if i % 2 == 0 and li[i] != 0:
			cnt += 1
		elif i % 2 == 1 and li[i] != 1:
			cnt += 1
	print(cnt // 2)


T = int(input())
D = []
for i in range(0, T):
	n = int(input())
	A = [int(x) for x in input().split(' ')]
	B = [x % 2 for x in A]
	odd = 0
	even = 0
	for j in range(0, len(B)):
		if (B[j] - j) % 2 == 1 and j % 2 == 0:
			even += 1
		elif (B[j] - j) % 2 == 1 and j % 2 == 1:
			odd += 1
	if odd == even:
		D.append(odd)
	else:
		D.append(-1)
for i in D:
	print(i)


t = int(input())
while t:
	t -= 1
	n = int(input())
	ar = list(map(int, input().split()))
	cnt = 0
	cnte = 0
	cnto = 0
	for (idx, i) in enumerate(ar):
		if idx % 2 != i % 2:
			cnt += 1
		if i % 2 == 1:
			cnto += 1
		else:
			cnte += 1
	if n % 2 == 0:
		if cnto == n // 2 and cnte == n // 2:
			if cnt % 2 == 0:
				print(cnt // 2)
			else:
				print(-1)
		else:
			print(-1)
	elif cnto == n // 2 and cnte == n // 2 + 1:
		if cnt % 2 == 0:
			print(cnt // 2)
		else:
			print(-1)
	else:
		print(-1)


ntest = int(input())
while ntest > 0:
	n = int(input())
	a = list(map(int, input().split()))
	cnt_wrong_odd = 0
	cnt_wrong_even = 0
	for i in range(0, len(a)):
		if i % 2 != a[i] % 2:
			if i % 2:
				cnt_wrong_odd += 1
			else:
				cnt_wrong_even += 1
	if cnt_wrong_odd != cnt_wrong_even:
		print(-1)
	else:
		print(cnt_wrong_odd)
	ntest -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	odd = sum(map(lambda x: x % 2, a))
	even = len(a) - odd
	o = len(a) // 2
	ans = 0
	if o != odd:
		print(-1)
	else:
		for i in range(1, len(a), 2):
			if a[i] % 2 == 0:
				ans += 1
		print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	even = 0
	good_even = 0
	odd = 0
	good_odd = 0
	for i in range(n):
		if a[i] % 2 == i % 2:
			if a[i] % 2 == 1:
				odd += 1
				good_odd += 1
			else:
				even += 1
				good_even += 1
		elif a[i] % 2 == 1:
			odd += 1
		else:
			even += 1
	if n % 2 == 0 and odd != even:
		print(-1)
		continue
	if n % 2 == 1 and even - odd != 1:
		print(-1)
		continue
	print(min(n // 2 + n % 2 - good_even, n // 2 - good_odd))


t = int(input())
while t:
	c = 0
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	r = []
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			l.append(a[i])
		if i % 2 != 0 and a[i] % 2 == 0:
			r.append(a[i])
	if len(l) != len(r):
		print(-1)
	else:
		print(len(l))
	t -= 1


t = int(input())
for x in range(t):
	a = int(input())
	thing = list(map(int, input().split()))
	corrects = []
	EvenY = 0
	EvenN = 0
	OddY = 0
	OddN = 0
	for y in range(len(thing)):
		if thing[y] % 2 == 0:
			if y % 2 == 0:
				corrects.append('Y')
				EvenY += 1
			else:
				corrects.append('N')
				EvenN += 1
		elif y % 2 == 1:
			corrects.append('Y')
			OddY += 1
		else:
			corrects.append('N')
			OddN += 1
	if EvenN != OddN:
		print(-1)
	else:
		print(EvenN)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	neg = 0
	pos = 0
	for i in range(n):
		if i % 2 != 0 and l[i] % 2 == 0:
			pos = pos + 1
		elif i % 2 == 0 and l[i] % 2 != 0:
			neg = neg + 1
	if pos == neg:
		print(pos)
	else:
		print(-1)


def main():
	t = int(input())
	data = []
	for test_i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		data.append(a)
	for a in data:
		bad = [0, 0]
		for (i, elem) in enumerate(a):
			if elem % 2 != i % 2:
				bad[elem % 2] += 1
		if bad[0] == bad[1]:
			print(bad[0])
		else:
			print('-1')
main()


t = int(input())
for i in range(0, t):
	n = int(input())
	o = list(map(int, input().split()))
	o1 = 0
	o2 = 0
	for j in range(0, n):
		if o[j] % 2 != j % 2:
			if j % 2 == 0:
				o1 += 1
			else:
				o2 += 1
	if o1 == o2:
		print(o1)
	else:
		print(-1)


import copy
for iii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	countodd = 0
	counteven = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2:
			countodd += 1
		elif i % 2 and arr[i] % 2 == 0:
			counteven += 1
		else:
			pass
	if counteven == countodd:
		print(countodd)
	else:
		print(-1)


t = int(input())
for i10 in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	s1 = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			s += 1
		if i % 2 == 1 and a[i] % 2 == 0:
			s1 += 1
	if s == s1:
		print(s)
	else:
		print(-1)


production = True
import sys, math

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = next_line.split()
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 1:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$')
		print(*args)

def solve():
	n = input(11)
	a = input(1)
	odd = 0
	even = 0
	diff = 0
	for (j, i) in enumerate(a):
		if i % 2 == 0:
			even += 1
		else:
			odd += 1
		if j % 2 != i % 2:
			diff += 1
	if n % 2 == 0:
		if odd != even:
			out(-1)
			return
	elif odd + 1 != even:
		out(-1)
		return
	out(diff // 2)
	return
for i in range(input(11)):
	solve()


import os
import sys
from io import BytesIO, IOBase
import threading
from collections import defaultdict

def seive(x):
	prime = [*range(x + 1)]
	for i in range(2, x + 1):
		if prime[i] == i:
			ind = i ** 2
			while ind < x + 1:
				if prime[ind] == ind:
					prime[ind] = i
				ind += i
	return prime

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		od = ev = 0
		for i in range(n):
			if i % 2 == 0 and arr[i] % 2 == 1:
				od += 1
			elif i % 2 == 1 and arr[i] % 2 == 0:
				ev += 1
		if od == ev:
			print(od)
		else:
			print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	n = inin()
	a = lin()
	(even, odd, even_idx, odd_idx) = (0, 0, 0, 0)
	c = 0
	for i in range(n):
		if a[i] % 2 == 0:
			even += 1
		else:
			odd += 1
		if i % 2 == 0:
			even_idx += 1
		else:
			odd_idx += 1
	if even != even_idx or odd_idx != odd:
		print(-1)
	else:
		for i in range(n):
			if a[i] % 2 != i % 2:
				c += 1
		print(c // 2)


t = int(input())
kn = 0
k = 0
kk = 0
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	for j in range(len(a)):
		if a[j] % 2 == 0 and j % 2 != 0 or (a[j] % 2 != 0 and j % 2 == 0):
			kn += 1
			if a[j] % 2 == 0:
				kk += 1
			elif a[j] % 2 != 0:
				k += 1
	if kk != k or kn == 1:
		print(-1)
	else:
		print(k)
	k = 0
	kk = 0


t = int(input())
p = []
q = []
k = 0
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(len(l)):
		if l[i] % 2 == i % 2:
			continue
		elif l[i] % 2 != 0 and i % 2 == 0:
			p.append(l[i])
		elif l[i] % 2 == 0 and i % 2 != 0:
			q.append(l[i])
	if len(p) != len(q):
		print('-1')
		p.clear()
		q.clear()
	else:
		print(len(q))
		p.clear()
		q.clear()


def ans(n, a):
	freq = {0: 0, 1: 0}
	for i in range(n):
		if a[i] % 2 == i % 2:
			pass
		else:
			freq[a[i] % 2] += 1
	if freq[0] != freq[1]:
		return -1
	else:
		return freq[0]
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(ans(n, a))


import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def def_value():
	return 0
t = inp()
for _ in range(t):
	n = inp()
	odd = n // 2
	oddC = 0
	a = inlist()
	c = 0
	for i in range(n):
		if a[i] % 2 != 0:
			oddC += 1
		if i % 2 != 0:
			if a[i] % 2 == 0:
				c += 1
	if oddC != odd:
		print(-1)
	else:
		print(c)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		c = [0, 0]
		for i in range(n):
			if a[i] % 2 != i % 2:
				c[a[i] % 2] += 1
		if c[0] == c[1]:
			rr.append(c[0])
		else:
			rr.append(-1)
	return JA(rr, '\n')
print(main())


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ev = (n + 1) // 2
	od = n - ev
	exod = 0
	exev = 0
	for i in range(n):
		if a[i] & 1:
			od -= 1
		else:
			ev -= 1
		if i % 2 != a[i] % 2:
			if a[i] & 1:
				exod += 1
			else:
				exev += 1
	ans = 0
	if ev != 0 or od != 0:
		ans = -1
	else:
		ans = exod
	print(ans)


for _ in range(int(input())):
	N = int(input())
	nums = list(map(int, input().split()))
	odd = N // 2
	even = (N + 1) // 2
	notinplace = 0
	oddnew = 0
	evennew = 0
	for i in range(N):
		if i % 2 != nums[i] % 2:
			notinplace += 1
			if nums[i] % 2 == 0:
				evennew += 1
			else:
				oddnew += 1
		elif nums[i] % 2 == 0:
			evennew += 1
		else:
			oddnew += 1
	if oddnew == odd and evennew == even:
		print(notinplace // 2)
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))
	(ee, oo) = (0, 0)
	for i in range(len(num)):
		if i % 2 == 0 and num[i] % 2 != 0:
			ee += 1
		elif i % 2 == 1 and num[i] % 2 != 1:
			oo += 1
		else:
			pass
	if oo != ee:
		print(-1)
	else:
		print(oo)


for _ in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	(c, e, o) = (0, 0, 0)
	for i in range(n):
		if a[i] % 2 != i % 2:
			if not i % 2 and a[i] % 2:
				e += 1
			else:
				o += 1
	if e == o:
		print(o)
	else:
		print(-1)


def solve(n, a):
	cnt = [0, 0]
	for (i, v) in enumerate(a):
		if v % 2 != i % 2:
			cnt[i % 2] += 1
	if cnt[0] == cnt[1]:
		return cnt[0]
	return -1
t = int(input())
for i_t in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	print(solve(n, a))


def ans(A):
	for i in range(len(A)):
		A[i] = A[i] % 2
	num_zeros = len([a for a in A if a == 0])
	num_ones = len([a for a in A if a == 1])
	if len(A) % 2 == 0:
		if not num_ones == num_zeros:
			return -1
		else:
			mismatches = 0
			for (i, a) in enumerate(A):
				if i % 2 != a:
					mismatches += 1
			return mismatches // 2
	elif not num_ones == num_zeros - 1:
		return -1
	else:
		mismatches = 0
		for (i, a) in enumerate(A):
			if i % 2 != a:
				mismatches += 1
		return mismatches // 2
T = int(input())
for t in range(T):
	input()
	A = input().split(' ')
	A = [int(x) for x in A]
	print(ans(A))


for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	ev = 0
	odd = 0
	for i in range(n):
		if i % 2 != ls[i] % 2:
			if i % 2 == 0:
				ev += 1
			else:
				odd += 1
	if ev == odd:
		print(ev)
	else:
		print(-1)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	(even, odd, count) = (0, 0, 0)
	for x in range(n):
		if a[x] % 2 == 0:
			even += 1
		else:
			odd += 1
		if x % 2 != a[x] % 2:
			count += 1
	if odd > even:
		print('-1')
	elif even - odd > 1:
		print('-1')
	else:
		print(count // 2)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	odd = 0
	even = 0
	for i in arr:
		if i % 2 == 0:
			even += 1
		else:
			odd += 1
	moda = [x % 2 for x in arr]
	modi = [i % 2 for i in range(n)]
	if n % 2 == 0 and odd != even:
		print(-1)
		continue
	elif n % 2 != 0 and even != odd + 1:
		print(-1)
		continue
	else:
		cnt = 0
		for i in range(n):
			if moda[i] == 1 and modi[i] == 0:
				cnt += 1
			elif moda[i] == 0 and modi[i] == 1:
				cnt += 1
			else:
				pass
		print(cnt // 2)


test = int(input())
while test != 0:
	n = int(input())
	arr = [int(x) for x in input().split()]
	even = 0
	odd = 0
	for i in range(n):
		if arr[i] & 1 == 1 and i & 1 != 1:
			odd += 1
		elif arr[i] & 1 == 0 and i & 1 != 0:
			even += 1
	if odd == even:
		print(odd)
	else:
		print(-1)
	test -= 1


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	count0 = 0
	count1 = 0
	for i in range(n):
		if arr[i] % 2 != i % 2:
			if i % 2 == 1:
				count1 += 1
			else:
				count0 += 1
	if count0 == count1:
		print(count0)
	else:
		print('-1')


t = int(input())
for p in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	cnt1 = 0
	for i in range(0, n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				cnt += 1
		elif a[i] % 2 != 1:
			cnt1 += 1
	if cnt1 == cnt:
		print((cnt + cnt1) // 2)
	else:
		print('-1')


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	(odd, even) = (len(a) // 2, len(a) - len(a) // 2)
	if len([x for x in a if x & 1]) == odd and len([x for x in a if not x & 1]) == even:
		print(len([x for (x, i) in enumerate(a) if x & 1 != i & 1]) // 2)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	odds = 0
	evens = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 == 1:
			odds += 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			evens += 1
	if evens != odds:
		print(-1)
	else:
		print(evens)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	e = 0
	o = 0
	e1 = 0
	o1 = 0
	for i in range(len(l)):
		if l[i] % 2 != 0 and i % 2 == 0:
			e = e + 1
		if l[i] % 2 == 0 and i % 2 == 1:
			o = o + 1
	if e != o:
		print(-1)
	else:
		print(e)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	oddpos = n // 2
	evenpos = n - oddpos
	evenel = 0
	oddel = 0
	oddwrong = 0
	evenwrong = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			evenel += 1
			if i % 2 != 0:
				evenwrong += 1
		else:
			oddel += 1
			if i % 2 == 0:
				oddwrong += 1
	if evenel != evenpos or oddel != oddpos:
		print(-1)
	else:
		print(evenwrong)


t = int(input())
for i in range(t):
	n = int(input())
	aa = [int(a) for a in input().split()]
	odd = 0
	eve = 0
	for i in range(n):
		if i % 2 == 0 and aa[i] % 2 == 1:
			odd += 1
		elif i % 2 == 1 and aa[i] % 2 == 0:
			eve += 1
	if odd == eve:
		print(odd)
	else:
		print('-1')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	o1 = 0
	o2 = 0
	for j in range(n):
		if j % 2 != a[j] % 2:
			x += 1
			if a[j] % 2 == 0:
				o1 += 1
			else:
				o2 += 1
	if x % 2 != 0:
		print(-1)
	elif o1 == o2:
		print(o1)
	else:
		print(-1)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) % 2 for x in input().split()]
	zeros = arr.count(0)
	ones = arr.count(1)
	if zeros == (n + 1) // 2 and ones == n // 2:
		c = 0
		for x in range(n):
			if x & 1 != arr[x]:
				c += 1
		print(c // 2)
	else:
		print(-1)


N = int(input())
for i in range(N):
	n = int(input())
	a = list(map(int, input().split()))
	go = ge = bo = be = 0
	for j in range(n):
		if j % 2 == 0:
			if a[j] % 2 == 0:
				ge += 1
			else:
				bo += 1
		elif a[j] % 2 == 0:
			be += 1
		else:
			go += 1
	if be != bo:
		print(-1)
	else:
		print(be)


t = int(input())
totals = []
for i in range(t):
	n = int(input())
	line = input().split()
	q_even = 0
	q_odd = 0
	for j in range(len(line)):
		if j % 2 != int(line[j]) % 2:
			if j % 2 == 1:
				q_odd += 1
			else:
				q_even += 1
	if q_odd == q_even:
		totals.append(q_odd)
	else:
		totals.append(-1)
for i in range(t):
	print(totals[i])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(odd, even) = (0, 0)
	(odd_p, even_p) = (0, 0)
	for i in range(n):
		if a[i] % 2 != i % 2:
			if a[i] % 2 == 0:
				even += 1
			else:
				odd += 1
			if i % 2 == 0:
				even_p += 1
			else:
				odd_p += 1
	if odd != odd_p or even != even_p:
		print(-1)
		continue
	print((odd + even) // 2)


for _ in range(int(input())):
	n = int(input())
	even = 0
	odd = 0
	arr = list(map(int, input().split()))
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 == 1:
			even += 1
		if i % 2 == 1 and arr[i] % 2 == 0:
			odd += 1
	total = even + odd
	if even != odd:
		print(-1)
		continue
	print(total // 2)


n = int(input())
b = []
for i in range(n):
	a = int(input())
	s = list(map(int, input().split()))
	k = 0
	d = 0
	for j in range(a):
		if s[j] % 2 == 1 and j % 2 == 0:
			k += 1
		elif s[j] % 2 == 0 and j % 2 == 1:
			d += 1
	if k != d:
		b.append(-1)
	else:
		b.append(k)
for h in range(n):
	print(b[h])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	n = int(ri())
	a = Ri()
	(cnte, cnto) = (0, 0)
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			if i % 2 == 1:
				cnto += 1
			else:
				cnte += 1
	if cnto != cnte:
		print(-1)
	else:
		print(cnto)


c = []
for i in range(int(input())):
	input()
	c.append(input().split())
for elem in c:
	n = 0
	k = 0
	e = 0
	for i in range(len(elem)):
		if i % 2 != int(elem[i]) % 2:
			e += 1
		if i % 2 == 0:
			k += 1
		if int(elem[i]) % 2 == 0:
			n += 1
	if e == 0:
		print(0)
	elif k != n or e % 2 != 0:
		print(-1)
	else:
		print(e // 2)


for i in range(int(input())):
	n = int(input())
	A = input().split(' ')
	misodd = 0
	miseven = 0
	for j in range(n):
		if (int(A[j]) - j) % 2 != 0:
			if j % 2 == 0:
				miseven += 1
			else:
				misodd += 1
	if misodd == miseven:
		print(misodd)
	else:
		print(-1)


from sys import stdin
input = stdin.readline
INF = 10 ** 9 + 7
MAX = 10 ** 7 + 7
MOD = 10 ** 9 + 7
for Ti in range(int(input().strip())):
	n = int(input().strip())
	a = [int(x) for x in input().strip().split()]
	(ans, eo) = (0, [0, 0])
	alen = len(a)
	for ai in range(alen):
		if a[ai] % 2 != ai % 2:
			eo[ai % 2] += 1
	if eo[0] == eo[1]:
		print(eo[0])
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	flag = 0
	pair = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			flag += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			pair += 1
	if flag == pair:
		print(pair)
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	zero = 0
	one = 0
	i = 0
	for x in a:
		if x % 2 != i % 2:
			if x % 2 == 0:
				zero = zero + 1
			else:
				one = one + 1
		i = i + 1
	if zero != one:
		print('-1')
	else:
		print(zero)


import sys, collections, math

def in_out():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	odd = 0
	even = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			odd += 1
		if i % 2 != 0 and arr[i] % 2 == 0:
			even += 1
	if odd == 0 and even == 0:
		print(0)
	elif odd == even:
		print(odd)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	if n % 2 != 0:
		a = []
		c_even = 0
		c_odd = 0
		not_even = 0
		not_odd = 0
		for i in range(n):
			a.append(lst[i] % 2)
			if lst[i] % 2 == 0:
				c_even += 1
			else:
				c_odd += 1
		if c_even <= c_odd:
			print(-1)
		else:
			for i in range(n):
				if i % 2 == 0 and a[i] % 2 != 0:
					not_even += 1
				elif i % 2 == 1 and a[i] % 2 != 1:
					not_odd += 1
			if not_even != not_odd:
				print(-1)
			else:
				print(not_even)
	else:
		a = []
		c_even = 0
		c_odd = 0
		not_even = 0
		not_odd = 0
		for i in range(n):
			a.append(lst[i] % 2)
			if lst[i] % 2 == 0:
				c_even += 1
			else:
				c_odd += 1
		if c_even != c_odd:
			print(-1)
		else:
			for i in range(n):
				if i % 2 == 0 and a[i] % 2 != 0:
					not_even += 1
				elif i % 2 == 1 and a[i] % 2 != 1:
					not_odd += 1
			if not_even != not_odd:
				print(-1)
			else:
				print(not_even)


q = int(input())
d = []
for i in range(q):
	a = int(input())
	c = list()
	cntf = 0
	cnt1 = 0
	cnt11 = 0
	b = [int(x) for x in input().split()]
	for i in range(len(b)):
		c.append(b[i] % 2)
		if b[i] % 2 == 0:
			cnt1 += 1
		if i % 2 == 0:
			cnt11 += 1
	if cnt1 != cnt11:
		d.append(-1)
	else:
		for i in range(len(c)):
			if i % 2 != c[i]:
				cntf += 1
		d.append(cntf // 2)
for i in range(len(d)):
	print(d[i])


import math

def shrey():
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	c1 = 0
	for i in range(len(a)):
		if i % 2 == 0 and a[i] % 2 != 0:
			c += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			c1 += 1
	if c != c1:
		print(-1)
	else:
		print(c)
T = input()
T = int(T)
for q in range(1, T + 1):
	shrey()


def num():
	return int(input())

def line():
	return map(int, input().split())
from itertools import repeat
t = num()
for _ in repeat(None, t):
	n = num()
	a = line()
	bad = [0, 0]
	for (i, x) in enumerate(a):
		if i % 2 != x % 2:
			bad[i % 2] += 1
	if bad[0] == bad[1]:
		print(bad[0])
	else:
		print(-1)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	ep = 0
	op = 0
	for i in range(N):
		if i % 2 != A[i] % 2:
			if i % 2 == 0:
				ep = ep + 1
			else:
				op = op + 1
	if ep == op:
		print(ep)
	else:
		print(-1)


def process():
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	bad_odd = []
	bad_even = []
	for (i, elem) in enumerate(a):
		if i % 2 != elem % 2:
			arr = bad_even if i % 2 == 0 else bad_odd
			arr.append(i)
	if len(bad_even) != len(bad_odd):
		print(-1)
	else:
		print(len(bad_even))
t = int(input())
for _ in range(t):
	process()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	evennot = 0
	oddnot = 0
	for j in range(0, n, 2):
		if a[j] % 2 != 0:
			evennot += 1
	for j in range(1, n, 2):
		if a[j] % 2 != 1:
			oddnot += 1
	if evennot == oddnot:
		print(evennot)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(ans, c) = (0, 0)
	for i in range(len(a)):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				ans += 1
				c += 1
		elif a[i] % 2 == 0:
			c = c - 1
	if c == 0:
		print(ans)
	else:
		print(-1)


from sys import stdin
num_tests = int(stdin.readline())

def make_good():
	n = int(stdin.readline().rstrip('\n'))
	arr = [int(x) for x in stdin.readline().rstrip('\n').split()]
	bad_odd = 0
	bad_even = 0
	for i in range(len(arr)):
		if i % 2 and (not arr[i] % 2):
			bad_odd += 1
		elif not i % 2 and arr[i] % 2:
			bad_even += 1
	if bad_odd != bad_even:
		print(-1)
	else:
		print(bad_odd)
for _ in range(num_tests):
	make_good()


t = int(input(''))
for i in range(t):
	n = int(input(''))
	s = input('')
	L = s.split(' ')
	for i in range(n):
		L[i] = int(L[i])
	co = 0
	ce = 0
	for i in range(n):
		if i % 2 == 0:
			if L[i] % 2 == 1:
				ce += 1
		elif L[i] % 2 == 0:
			co += 1
	if co != ce:
		print(-1)
	else:
		print(co)


t = int(input())
for i in range(0, t):
	n = int(input())
	l = []
	l = list(map(int, input().split()))
	(ce, we) = (0, 0)
	for i in range(0, n):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				ce = ce + 1
		elif l[i] % 2 != 1:
			we = we + 1
	if ce == we:
		print(ce)
	else:
		print('-1')


t = int(input())
for caseNr in range(1, t + 1):
	n = int(input())
	a = list(map(int, input().split()))
	evens = 0
	odds = 0
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				evens += 1
			else:
				odds += 1
	if evens == odds:
		print(evens)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def yes():
	print('Yes')

def no():
	print('No')
Testcase = inin()
for _ in range(Testcase):
	n = inin()
	a = inar()
	odd = 0
	even = 0
	for i in range(n):
		if a[i] % 2 == i % 2:
			continue
		elif a[i] % 2:
			odd += 1
		else:
			even += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	pt = 0
	n0 = 0
	n1 = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			n0 += 1
		else:
			n1 += 1
		if arr[i] % 2 != pt:
			ans += 1
		if pt == 0:
			pt = 1
		else:
			pt = 0
	if n % 2 == 0:
		if n0 == n1:
			print(ans // 2)
		else:
			print(-1)
	elif n0 == n1 + 1:
		print(ans // 2)
	else:
		print(-1)

def main():
	t = int(input())
	while t:
		solve()
		t -= 1
main()


import os
import sys
from io import BytesIO, IOBase

def solution(arr, n):
	odds = sum((1 for x in arr if x & 1))
	eves = n - odds
	if n & 1 == 0:
		if odds != eves:
			write(-1)
			return
		ne = 0
		for i in range(n):
			if i & 1 and arr[i] & 1 == 0:
				ne += 1
		write(ne)
	else:
		if eves - odds != 1:
			write(-1)
			return
		ne = 0
		for i in range(n):
			if i & 1 and arr[i] & 1 == 0:
				ne += 1
		write(ne)

def main():
	for _ in range(r_int()):
		n = r_int()
		arr = r_array()
		solution(arr, n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


n = int(input())
for i in range(n):
	st = input()
	lis = list(map(int, input().split()))
	k = 0
	k1 = 0
	k2 = 0
	for i in range(0, len(lis), 2):
		if lis[i] % 2 == 0:
			k = k + 1
		else:
			k1 = k1 + 1
	for i in range(1, len(lis), 2):
		if lis[i] % 2 != 0:
			k = k + 1
		else:
			k2 = k2 + 1
	if k == len(lis):
		print(0)
	elif k1 == k2:
		print(int(k1))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	chan = 0
	le = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				chan += 1
			else:
				le += 1
	if chan == le:
		print(le)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	(count1, count2) = (0, 0)
	for i in range(n):
		if i % 2 != a[i] % 2:
			if a[i] % 2 > 0:
				count2 = count2 + 1
			else:
				count1 = count1 + 1
	if count1 != count2:
		print(-1)
	else:
		print(count1)


def counter(n, array):
	count_even = 0
	count_odd = 0
	for i in range(n):
		if i % 2 == 0 and array[i] % 2 != 0:
			count_even += 1
		if i % 2 != 0 and array[i] % 2 != 1:
			count_odd += 1
	if count_even == count_odd:
		return count_even
	else:
		return -1
input_n = int(input())
for i in range(input_n):
	n = int(input())
	array = input().split(' ')
	array = [int(i) for i in array]
	print(counter(n, array))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	d = str(input())
	s = d.split()
	z = 0
	oa = 0
	ea = 0
	ol = 0
	el = 0
	for i in s:
		i = int(i)
		idx = z
		if i % 2 == idx % 2:
			z += 1
			continue
		else:
			if i % 2 == 1:
				oa += 1
			elif i % 2 == 0:
				ea += 1
			if idx % 2 == 1:
				ol += 1
			elif idx % 2 == 0:
				el += 1
		z += 1
	if oa == ol and ea == el:
		ans = oa
		print(ans)
	else:
		print(-1)


T = int(input())
for i in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = 0
	c = 0
	flag = 0
	if a[0] % 2 != 0:
		b = b + 1
	if n > 1:
		if a[1] % 2 == 0:
			c = c + 1
	if n > 1:
		for j in range(2, n):
			if j % 2 == 0:
				if a[j] % 2 != 0:
					b = b + 1
			elif a[j] % 2 == 0:
				c = c + 1
	if b != c:
		print('-1')
	else:
		print(b)


def ans(n, a):
	bad_even = 0
	bad_odd = 0
	for i in range(len(a)):
		if i % 2 == 1 and a[i] % 2 == 0:
			bad_odd += 1
		if i % 2 == 0 and a[i] % 2 == 1:
			bad_even += 1
	if bad_even == bad_odd:
		return bad_even
	return -1
m = int(input())
for i in range(m):
	n = int(input())
	arr = input().split()
	a = []
	for i in arr:
		a.append(int(i))
	print(ans(n, a))


import os
import sys
from io import BytesIO, IOBase
import math

def inputIntArray():
	return list(map(int, input().rstrip().split()))

def inputArray():
	return input().rstrip().split()

def inputVars():
	return map(int, input().rstrip().split())

def inputNum():
	return int(input())
sys.setrecursionlimit(100000)

def main():
	for _ in range(inputNum()):
		n = inputNum()
		arr = inputIntArray()
		cntForPosRem0 = 0
		cntForPosRem1 = 0
		for pos in range(n):
			if arr[pos] % 2 != pos % 2:
				if pos % 2 == 0:
					cntForPosRem0 += 1
				else:
					cntForPosRem1 += 1
		if cntForPosRem0 != cntForPosRem1:
			print(-1)
		else:
			print(cntForPosRem1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


arr = []
for i in range(int(input())):
	input()
	arr.append(list(map(int, input().split())))
for x in arr:
	(odd, even) = ([], [])
	for i in range(len(x)):
		if i % 2 != x[i] % 2:
			if i % 2 == 0:
				even.append(i)
			else:
				odd.append(i)
	(o, e) = (len(odd), len(even))
	if o == 0 and e == 0:
		print(0)
	elif o != e:
		print(-1)
	else:
		print(o)


for i in range(int(input())):
	_ = input()
	a = list(map(int, input().split()))
	ec = 0
	oc = 0
	for i in range(len(a)):
		if i % 2 == 0 and a[i] % 2 != 0:
			ec += 1
		if i % 2 == 1 and a[i] % 2 == 0:
			oc += 1
	if ec == oc:
		print(ec)
	else:
		print(-1)


m = int(input())
for i in range(m):
	n = int(input())
	a = [0] * n
	eo = 0
	oe = 0
	s = 0
	a = list(map(int, input().split(' ')))
	for i in range(n):
		if i % 2 == a[i] % 2:
			continue
		else:
			s = s + 1
			if a[i] % 2 == 0:
				eo = eo + 1
			else:
				oe = oe + 1
	if oe == eo and 2 * oe == s:
		print(eo)
	else:
		print(-1)


import sys
inpy = [int(x) for x in sys.stdin.read().split()]
t = inpy[0]
index = 1
for _ in range(t):
	n = inpy[index]
	nums = inpy[index + 1:index + 1 + n]
	index += 1 + n
	cnt = [0] * 2
	for i in range(n):
		if i % 2 != nums[i] % 2:
			cnt[i % 2] += 1
	if cnt[0] != cnt[1]:
		print(-1)
	else:
		print(cnt[0])


t = int(input())
for cases in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = dict()
	e = o = 0
	c = 0
	for i in range(len(a)):
		if a[i] & 1 == i & 1:
			if a[i] % 2 == 0:
				e += 1
			else:
				o += 1
		elif a[i] % 2 == 0:
			c += 1
			e += 1
		else:
			o += 1
	if len(a) % 2 == 0:
		if e == o:
			print(c)
		else:
			print(-1)
	elif e - 1 == o:
		print(c)
	else:
		print(-1)


n = int(input())
for i in range(n):
	f = int(input())
	s = list(map(int, input().split(' ')))
	x = 0
	x1 = 0
	for i in range(f):
		if i % 2 != s[i] % 2 and i % 2 == 0:
			x1 += 1
		elif i % 2 != s[i] % 2 and i % 2 == 1:
			x += 1
	if x != x1:
		print('-1')
	else:
		print(x)


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['Yes', 'No']
test_case = ii()
while test_case:
	test_case -= 1
	n = ii()
	a = li()
	o = e = 0
	for i in range(n):
		if i % 2:
			if not a[i] % 2:
				o += 1
		elif a[i] % 2:
			e += 1
	print(e if e == o else -1)


t = int(input())
for s in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	(add, sub) = (0, 0)
	for j in range(n):
		if j % 2 == 0:
			if array[j] % 2 == 1:
				add += 1
		elif array[j] % 2 == 0:
			sub += 1
	if add == sub:
		print(add)
	else:
		print(-1)


t = int(input())
while t != 0:
	n = int(input())
	l = list(map(int, input().split()))
	even_at_odd = 0
	odd_at_even = 0
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				odd_at_even += 1
		elif l[i] % 2 == 0:
			even_at_odd += 1
	if even_at_odd == odd_at_even:
		print(even_at_odd)
	else:
		print('-1')
	t -= 1


from math import ceil
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	for i in range(n):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				c1 += 1
		elif l[i] % 2 != 1:
			c2 += 1
	if c1 == c2:
		print(c2)
	else:
		print(-1)


test_case = int(input())
while test_case:
	n = int(input())
	a = list(map(int, input().split()))
	odd = []
	even = []
	for i in range(n):
		if i % 2 != a[i] % 2:
			odd.append(i) if a[i] % 2 else even.append(i)
	print(-1 if len(odd) != len(even) else len(odd))
	test_case -= 1


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	odd = 0
	even = 0
	wrong = 0
	for i in range(N):
		if i % 2 != A[i] % 2:
			wrong += 1
		if A[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	if N % 2 == 1 and N // 2 == odd and (N // 2 == even - 1):
		print(wrong // 2)
	elif N % 2 == 0 and N // 2 == odd and (N // 2 == even):
		print(wrong // 2)
	else:
		print(-1)


for o in range(int(input())):
	even = 0
	odd = 0
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(len(arr)):
		if i % 2 == 0 and arr[i] % 2 != 0:
			even += 1
		elif i % 2 == 1 and arr[i] % 2 != 1:
			odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


tc = int(input())
while tc > 0:
	si = int(input())
	k = list(map(int, input().split()))
	e = 0
	o = 0
	ct = 0
	for i in k:
		if i % 2 == 0:
			e += 1
		else:
			o += 1
	if si % 2 == 0 and o != e or (si % 2 != 0 and o + 1 != e):
		print('-1')
	else:
		for i in range(si):
			if i % 2 == 0 and k[i] % 2 != 0 or (i % 2 != 0 and k[i] % 2 == 0):
				ct += 1
		print(ct // 2)
	tc -= 1


import sys
import random
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
for t in range(int(input())):
	n = int(input())
	arr = intInp()
	e = 0
	o = 0
	for i in range(n):
		if i % 2 == 0:
			if not arr[i] % 2 == 0:
				e += 1
		elif arr[i] % 2 == 0:
			o += 1
	if o == e:
		print(o)
	else:
		print(-1)


t = int(input())
for t1 in range(t):
	n = int(input())
	a = [int(n1) for n1 in input().split()]
	even = []
	odd = []
	for i in range(len(a)):
		if i % 2 == a[i] % 2:
			pass
		elif a[i] % 2 == 0:
			even.append(a[i])
		else:
			odd.append(a[i])
	if len(even) == len(odd):
		print(len(even))
	else:
		print(-1)


Answers = []
for i in range(int(input())):
	N = int(input())
	X = [0, 0]
	Array = list(map(int, input().split()))
	for j in range(N):
		X[j % 2] += 1 if j % 2 != Array[j] % 2 else 0
	Answers.append(str(X[0] if X[0] == X[1] else -1))
print('\n'.join(Answers))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))[:n]
	m = []
	d = []
	for i in range(n):
		k = l[i] % 2
		m.append(k)
	for i in range(len(m)):
		if i % 2 != m[i]:
			d.append(m[i])
	dl = len(d)
	if d.count(1) == d.count(0):
		ans = len(d) // 2
		print(ans)
	else:
		ans = -1
		print(ans)


t = int(input())
for test in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	e = 0
	o = 0
	c = 0
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] % 2 == 0:
				c += 1
			else:
				e += 1
		if i % 2 != 0:
			if l[i] % 2 != 0:
				c += 1
			else:
				o += 1
	if c == n:
		print(0)
	elif e == o:
		print(e)
	else:
		print(-1)


t = int(input())
for q in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	eo = 0
	oe = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 == 1:
			eo += 1
		elif i % 2 == 1 and arr[i] % 2 == 0:
			oe += 1
	if eo == oe:
		print(eo)
	else:
		print(-1)


n = int(input())
for i in range(n):
	cou1 = 0
	cou2 = 0
	input()
	s = [int(x) for x in input().split(' ')]
	for i in range(len(s)):
		if i % 2 != s[i] % 2:
			if i % 2 == 0:
				cou1 += 1
			else:
				cou2 += 1
	if cou1 == cou2:
		print(cou1)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	lst = []
	eve = 0
	odd = 0
	diff = 0
	lst = list(map(int, input().split()))
	for j in range(n):
		if lst[j] % 2 == 0:
			eve += 1
		else:
			odd += 1
		if lst[j] % 2 != j % 2:
			diff += 1
	if n % 2 == 0 and eve != odd or (n % 2 == 1 and eve != odd + 1):
		print(-1)
	else:
		print(diff // 2)


def main():
	t = int(input())
	collect = []
	for i in range(t):
		x = int(input())
		collect.append(list(map(int, input().split())))
	for entry in collect:
		o_arr = 0
		e_arr = 0
		for i in range(len(entry)):
			if i % 2 != entry[i] % 2:
				if i % 2 == 0:
					o_arr += 1
				else:
					e_arr += 1
		if o_arr != e_arr:
			print(-1)
		else:
			print(o_arr)
main()


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def list_input():
	return list(map(int, input().split()))

def sep_input():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	l = list_input()
	if n == 1:
		if l[0] % 2 == 0:
			print(0)
		else:
			print(-1)
	else:
		ev = 0
		od = 0
		for i in range(n):
			if l[i] % 2 == 1:
				od += 1
			else:
				ev += 1
		if n % 2 == 0 and od != ev:
			print(-1)
			continue
		if n % 2 == 1 and od + 1 != ev:
			print(-1)
			continue
		c = 0
		for i in range(n):
			if l[i] % 2 != i % 2:
				c += 1
		print(c // 2)


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	parity = [True if elm % 2 == 0 else False for elm in l]
	if parity.count(False) != n // 2:
		print(-1)
	else:
		print([True if elm % 2 == ind % 2 else False for (ind, elm) in enumerate(l)].count(False) // 2)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % 2
	binary = [0] * n
	bin = 1
	for i in range(1, n, 2):
		binary[i] = bin
	count1 = 0
	count0 = 0
	for i in range(n):
		if binary[i] == 0:
			if a[i] == 1:
				count1 += 1
		elif a[i] == 0:
			count0 += 1
	if count1 == count0:
		print(count1)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	odd_wrong = 0
	odd = 0
	even = 0
	even_wrong = 0
	right = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			even = even + 1
			if i % 2 == 0:
				right = right + 1
			else:
				even_wrong = even_wrong + 1
		else:
			odd = odd + 1
			if i % 2 != 0:
				right = right + 1
			else:
				odd_wrong = odd_wrong + 1
	if right == n:
		print(0)
	elif even_wrong == odd_wrong:
		print(even_wrong)
	else:
		print(-1)


for _ in range(int(input())):
	(p, o, _) = (0, 0, input())
	for (i, e) in enumerate(map(int, input().split())):
		if i % 2 and (not e % 2):
			p += 1
		elif not i % 2 and e % 2:
			o += 1
	print(o if o == p else -1)


t = int(input())
for __ in range(t):
	l = int(input())
	x = [int(i) for i in input().split()]
	(s, q) = (0, 0)
	for j in range(0, l, 2):
		if x[j] % 2 != j % 2:
			s += 1
	for i in range(1, l, 2):
		if x[i] % 2 != i % 2:
			q += 1
	if s == q:
		print(s)
	else:
		print('-1')


m = int(input())
for j in range(m):
	n = int(input())
	l = list(map(int, input().strip().split()))[:n]
	a = [0, 0]
	for i in range(n):
		if i % 2 == 0:
			x = 0
		else:
			x = 1
		if l[i] % 2 != x:
			a[x] += 1
	if a[0] == a[1]:
		print(a[0])
	else:
		print(-1)


m = 10 ** 9 + 7
t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(n):
		if l[i] % 2 != i % 2:
			if i % 2 == 0:
				o += 1
			else:
				e += 1
	if o != e:
		print(-1)
		continue
	else:
		print(o)


cases = int(input())
for v in range(cases):
	n = int(input())
	a = list(map(int, input().strip().split()))
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			even += 1
		if i % 2 != 0 and a[i] % 2 == 0:
			odd += 1
	if odd == even:
		print(even)
	else:
		print(-1)


num = int(input())
for fff in range(num):
	n = int(input())
	a = list(map(int, input().split(' ')))
	cnt0 = 0
	cnt1 = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				cnt0 += 1
			if i % 2 == 1:
				cnt1 += 1
	if cnt0 != cnt1:
		print('-1')
	else:
		print(cnt0)


def b():
	n = int(input())
	a = list(map(int, input().split()))
	(a_par, a_impar) = (0, 0)
	for (i, n) in enumerate(a):
		if n % 2 != i % 2:
			if i % 2 == 0:
				a_par += 1
			else:
				a_impar += 1
	if a_par != a_impar:
		print(-1)
	else:
		print(a_par)

def main():
	for _ in range(int(input())):
		b()
main()


t = int(input())
for num in range(0, t):
	n = int(input())
	array = []
	gstr = input().split(' ')
	for i in range(0, n):
		array.append(int(gstr[i]))
	odd = 0
	even = 0
	for i in range(len(array)):
		if i % 2 != array[i] % 2:
			if i % 2 == 1:
				odd = odd + 1
			else:
				even = even + 1
	if even == odd:
		print(even)
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	oddExceptions = 0
	evenExceptions = 0
	for i in range(n):
		if a[i] % 2 == 0 and i % 2 != 0:
			evenExceptions += 1
		elif a[i] % 2 != 0 and i % 2 == 0:
			oddExceptions += 1
	if oddExceptions == evenExceptions:
		print(evenExceptions)
		continue
	else:
		print(-1)


def even_array(arr):
	even = 0
	odd = 0
	for i in range(len(arr)):
		if arr[i] % 2 != i % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if even != odd:
		return -1
	else:
		return even
a = input()
for i in range(int(a)):
	x = int(input())
	arr = list(map(int, input().split()))
	print(even_array(arr))


import math
from io import BytesIO, IOBase
import sys
import os

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))

def main():
	t = Iint()
	for _ in range(t):
		n = Iint()
		a = Ilist()
		x = [ai % 2 - i % 2 for (i, ai) in enumerate(a)]
		i = x.count(-1)
		j = x.count(1)
		if i == j:
			print(i)
		else:
			print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


a = int(input())
for i in range(a):
	x = int(input())
	odd = 0
	eve = 0
	z = list(map(int, input().split()))
	for i in range(len(z)):
		if z[i] % 2 != i % 2:
			if i % 2 == 1:
				odd += 1
			else:
				eve += 1
	if odd == eve:
		print(odd)
	else:
		print(-1)


def solver(array):
	(nb_odd_to_swap, nb_even_to_swap) = (0, 0)
	for (i, v) in enumerate(array):
		if not i % 2 == v % 2:
			if v % 2 == 0:
				nb_even_to_swap += 1
			else:
				nb_odd_to_swap += 1
	return nb_even_to_swap if nb_even_to_swap == nb_odd_to_swap else -1
n = int(input())
test = []
for _ in range(n):
	l = int(input())
	array = list(map(int, str(input()).split()))
	print(solver(array))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	ans.append(8)
	for i in range(n):
		if arr[i] % 2 != i % 2 and arr[i] % 2 == 0:
			ans.append(0)
		elif arr[i] % 2 != i % 2 and arr[i] % 2 != 0:
			ans.append(1)
	q = ans.count(0)
	w = ans.count(1)
	if q != w:
		print('-1')
	else:
		print(q)


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().strip().split()))
	(odd, even) = (0, 0)
	for (ind, a) in enumerate(array):
		if ind % 2 != a % 2:
			if a % 2 == 0:
				even += 1
			else:
				odd += 1
	print(odd if odd == even else -1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	evn = 0
	od = 0
	e = 0
	o = 0
	x = 0
	for i in range(len(l)):
		if l[i] % 2 == 1:
			od += 1
		else:
			evn += 1
	for i in range(len(l)):
		if i % 2 == 0:
			if i % 2 != l[i] % 2:
				e += 1
		elif i % 2 != l[i] % 2:
			o += 1
	if e != o:
		print(-1)
	else:
		print(o)


for i in range(int(input())):
	n = input()
	a = [int(i) % 2 for i in input().split()]
	(nonPar, nonImpar) = (len([i for i in a[::2] if i == 1]), len([i for i in a[1::2] if i == 0]))
	if nonPar == nonImpar:
		print(nonImpar)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	odd = 0
	even = 0
	notequal = 0
	for i in range(n):
		if l[i] % 2 == i % 2:
			if l[i] % 2 == 0:
				even += 1
			else:
				odd += 1
		else:
			notequal += 1
	if n % 2 == 0 and even == odd:
		print(notequal // 2)
	elif n % 2 == 1 and even == odd + 1:
		print(notequal // 2)
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	oddc = 0
	evencount = 0
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] % 2 != 0:
				evencount += 1
		elif l[i] % 2 == 0:
			oddc += 1
	if evencount == oddc:
		print(oddc)
	else:
		print('-1')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ones = 0
	zeros = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			zeros += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			ones += 1
	if zeros == ones:
		print(ones)
	else:
		print(-1)


from sys import stdin as lector
input = lector.readlines()
n = int(input[0])
for i in range(2, 2 * n + 1, 2):
	par = 0
	impar = 0
	bueno = 0
	malo = 0
	cadena = input[i].split(' ')
	for j in range(0, len(cadena)):
		if int(cadena[j]) % 2 == 0:
			par = par + 1
			if j % 2 == 0:
				bueno = bueno + 1
			else:
				malo = malo + 1
		elif int(cadena[j]) % 2 == 1:
			impar = impar + 1
			if j % 2 == 1:
				bueno = bueno + 1
			else:
				malo = malo + 1
	if malo % 2 == 1 or abs(par - impar) > 1:
		print(-1)
	else:
		print(int(malo / 2))


n = int(input())
for i in range(n):
	m = int(input())
	a = [int(i) for i in input().split()]
	d = []
	e = []
	c = 0
	for j in range(0, len(a)):
		d.append(j % 2)
		e.append(a[j] % 2)
	for j in range(0, len(d)):
		if d[j] != e[j]:
			c = c + 1
	f = d.count(0)
	g = d.count(1)
	h = e.count(1)
	z = e.count(0)
	if h == g and f == z:
		print(c // 2)
	elif c == 0:
		print(0)
	else:
		print(-1)


for i in range(int(input())):
	lst = list()
	lst1 = list()
	c = 0
	c1 = 0
	n = int(input())
	x = list(map(int, input().split()))
	if n == 1:
		if x[0] % 2 != 0:
			print(-1)
			continue
		else:
			print(0)
			continue
	for i in range(len(x)):
		if i % 2 == 0 and x[i] % 2 != 0:
			lst.append(x[i])
		elif i % 2 != 0 and x[i] % 2 == 0:
			lst1.append(x[i])
	if len(lst) != len(lst1):
		print(-1)
	else:
		print(len(lst))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(ch, nech) = (0, 0)
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				ch += 1
			else:
				nech += 1
	if ch == 0 and nech == 0:
		print(0)
		continue
	elif ch == nech:
		print(ch)
	else:
		print(-1)


import sys, math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	L = get_list()
	count = 0
	no_even = 0
	no_odd = 0
	for i in L:
		if i % 2 == 0:
			no_even += 1
		else:
			no_odd += 1
	for i in range(n):
		if L[i] % 2 != i % 2:
			count += 1
	if n == 1 and L[0] % 2 != 0 or no_even != (n + 1) // 2 or no_odd != n // 2:
		print(-1)
	else:
		print(int(math.ceil(count / 2)))


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	swap = 0
	even = 0
	odd = 0
	for i in range(n):
		x = i % 2
		y = l1[i] % 2
		if x != y:
			if y == 0:
				even += 1
			else:
				odd += 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	odd = 0
	even = 0
	for i in range(n):
		if (li[i] - i) % 2 == 0:
			continue
		if i % 2:
			odd += 1
		else:
			even += 1
	if odd != even:
		print(-1)
	else:
		print(odd)


def solution(array):
	misplaced_o = 0
	misplaced_e = 0
	for i in range(len(arr)):
		misplaced_o += 1 if int(array[i]) % 2 == 1 and i % 2 == 0 else 0
		misplaced_e += 1 if int(array[i]) % 2 == 0 and i % 2 == 1 else 0
	print(misplaced_e if misplaced_o == misplaced_e else -1)
t = int(input())
while t > 0:
	n = input()
	arr = input()
	arr = arr.split(' ')
	solution(arr)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	arr = map(int, input().split(' '))
	flaws = 0
	even = 0
	odd = 0
	for (index, item) in enumerate(arr):
		if index % 2 != item % 2:
			flaws += 1
			if item % 2 == 0:
				even += 1
			else:
				odd += 1
	if flaws == 0:
		print(0)
	elif flaws % 2 == 0:
		if even == odd:
			print(flaws // 2)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
for T in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	ce = 0
	nce = 0
	co = 0
	nco = 0
	i = 0
	while i < n:
		if li[i] % 2 == 0:
			ce += 1
		else:
			nce += 1
		i += 2
	i = 1
	while i < n:
		if li[i] % 2 == 1:
			co += 1
		else:
			nco += 1
		i += 2
	if nce == nco:
		print(nce)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	countod = 0
	countev = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			countev += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			countod += 1
	if countod != countev:
		print(-1)
	else:
		print(countev)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	correct_count = 0
	even_count = 0
	odd_count = 0
	length = n
	for i in range(0, len(a)):
		if i % 2 == 0 and a[i] % 2 == 0:
			correct_count += 1
			even_count += 1
		elif i % 2 == 1 and a[i] % 2 == 1:
			correct_count += 1
			odd_count += 1
	if correct_count == n:
		print('0')
	elif n % 2 == 0:
		if odd_count != even_count:
			print('-1')
		else:
			print(int((length - correct_count) / 2))
	elif odd_count + 1 == even_count:
		print(int((length - correct_count) / 2))
	else:
		print('-1')
	t = t - 1


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	swap = 0
	odd = 0
	even = 0
	for j in range(len(arr)):
		if j % 2 == arr[j] % 2:
			pass
		elif j % 2 == 1:
			odd += 1
		else:
			even += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


import sys
import heapq

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		nums = list(map(int, sys.stdin.readline().split()))
		oddCnt = 0
		evenCnt = 0
		for i in range(n):
			if i % 2 and nums[i] % 2 == 0:
				oddCnt += 1
			if i % 2 == 0 and nums[i] % 2:
				evenCnt += 1
		if oddCnt + evenCnt == 0:
			print(0)
			continue
		if oddCnt != evenCnt:
			print(-1)
		else:
			print(oddCnt)
	return
main()


from math import ceil

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().strip().split()))
		(mismatched, odd, even) = (0, 0, 0)
		for (index, num) in enumerate(a):
			if index & 1 ^ num & 1:
				mismatched += 1
			if num & 1:
				odd += 1
			else:
				even += 1
		(even_places, odd_places) = (ceil(n / 2.0), n - ceil(n / 2))
		if even != even_places or odd != odd_places:
			print(-1)
		else:
			print(mismatched // 2)
main()


from sys import stdin, stdout

def II():
	return int(stdin.readline())

def LI():
	return list(map(int, stdin.readline().split()))
t = II()
for _ in range(t):
	n = II()
	a = LI()
	(ans, odds, even) = (0, 0, 0)
	for (i, v) in enumerate(a):
		if i % 2 != v % 2:
			if i % 2 == 0:
				odds += 1
			else:
				even += 1
	if odds + even != 0:
		if odds == even:
			ans = odds
		else:
			ans = -1
	stdout.write(str(ans) + '\n')


t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ec = 0
	cc = 0
	for i in range(n):
		if a[i] % 2 == 0:
			ec += 1
		elif i % 2 == 0:
			cc += 1
	if ec == (n + 1) // 2:
		print(cc)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	oddCount = 0
	swapCount = 0
	for d in range(n):
		if p[d] % 2 != 0:
			oddCount += 1
		if d % 2 != p[d] % 2:
			swapCount += 1
	evenCount = n - oddCount
	if n == 1 and evenCount == 1:
		print(0)
	elif evenCount >= 1 and oddCount >= 1 and (oddCount == n // 2):
		print(swapCount // 2)
	else:
		print(-1)


import sys
lines = []
for line in sys.stdin:
	if 'Exit' == line.rstrip():
		break
	lines.append(line)
t = int(lines[0])
for case in range(1, 2 * t + 1, 2):
	n = int(lines[case])
	a = [int(x) for x in lines[case + 1].split(' ')]
	bad_odds = 0
	bad_evens = 0
	for i in range(len(a)):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				bad_evens += 1
			else:
				bad_odds += 1
	if bad_evens == bad_odds:
		print(bad_evens)
	else:
		print(-1)


cases = int(input())
counter_list = []
for case in range(cases):
	len = int(input())
	array_int = list(map(int, input().split()))
	counter_odd = 0
	counter_even = 0
	for a in range(array_int.__len__()):
		if a % 2 == 0 and array_int[a] % 2 != 0:
			counter_odd += 1
		if a % 2 != 0 and array_int[a] % 2 == 0:
			counter_even += 1
	if counter_odd == counter_even:
		counter_list.append(counter_odd)
	else:
		counter_list.append(-1)
for ele in counter_list:
	print(ele)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = [int(i) for i in input().split()]
	(e, o) = (0, 0)
	for i in range(n):
		if i % 2 != l1[i] % 2:
			if l1[i] % 2 == 0:
				e += 1
			else:
				o += 1
	if o == e:
		print((e + o) // 2)
	else:
		print(-1)


def get_good(n, L):
	ev = 0
	od = 0
	for i in range(n):
		if i % 2 == 0:
			if L[i] % 2 != 0:
				od += 1
		if i % 2 != 0:
			if L[i] % 2 == 0:
				ev += 1
	if ev != od:
		return -1
	else:
		return ev
t = int(input())
for _ in range(t):
	n = int(input())
	L = list(map(int, input().split()))
	print(get_good(n, L))


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		bad0 = 0
		bad1 = 0
		for i in range(n):
			if i % 2 == 0:
				if a[i] % 2 != 0:
					bad0 += 1
			elif a[i] % 2 != 1:
				bad1 += 1
		if bad0 != bad1:
			print(-1)
		else:
			print(bad0)
prog()


T = int(input())

def solve():
	N = int(input())
	A = list(map(int, input().split()))
	even_in_odd = 0
	odd_in_even = 0
	for (i, a) in enumerate(A):
		if a % 2 == 0 and i % 2 == 1:
			even_in_odd += 1
		if a % 2 == 1 and i % 2 == 0:
			odd_in_even += 1
	if even_in_odd == odd_in_even:
		return odd_in_even
	return -1
for _ in range(T):
	print(solve())


t = int(input())
for i in range(t):
	a = int(input())
	l = [int(i) for i in input().split()]
	l1 = [i % 2 for i in l]
	e = l1.count(0)
	o = a - e
	if len(l1) // 2 == o:
		l2 = [i % 2 for i in range(a)]
		l3 = [0 if l1[i] == l2[i] else 1 for i in range(a)]
		misplace = l3.count(1)
		if misplace % 2 == 0:
			print(misplace // 2)
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ei = [a[i] for i in range(len(a)) if i % 2 == 0 and a[i] % 2 != 0]
	oi = [a[i] for i in range(len(a)) if i % 2 != 0 and a[i] % 2 == 0]
	if len(ei) != len(oi):
		print(-1)
	else:
		print(len(ei))


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
t = int(input())
for test in range(t):
	n = int(input())
	arr = get_array()
	ne = 0
	no = 0
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if arr[i] % 2 == 0:
				ne += 1
			else:
				no += 1
	if ne == no:
		print(ne)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	cnto = cnte = 0
	o = e = 0
	for i in range(n):
		if s[i] % 2:
			if s[i] % 2 != i % 2:
				cnto += 1
			o += 1
		else:
			if s[i] % 2 != i % 2:
				cnte += 1
			e += 1
	print(-1 if e < (n + 1) // 2 or o < n // 2 else (cnto + cnte) // 2)


def main():
	for _ in range(int(input())):
		s = int(input())
		l = [int(i) for i in input().split()]
		el = [i for i in l[::2] if i % 2 != 0]
		ol = [i for i in l[1::2] if i % 2 == 0]
		if len(el) == len(ol):
			print(len(el))
		elif s == 1:
			if l[0] % 2 != 0:
				print(-1)
			else:
				print(0)
		else:
			print(-1)
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n % 2 == 0:
		ct_even = n // 2
		ct_odd = n // 2
	else:
		ct_even = n // 2 + 1
		ct_odd = n // 2
	even = 0
	odd = 0
	for i in range(n):
		if l[i] % 2 == 0:
			even += 1
		else:
			odd += 1
	ct1 = 0
	ct2 = 0
	i = 0
	if even == ct_even and odd == ct_odd:
		while i < n:
			if l[i] % 2 == 0:
				ct1 += 1
			i += 1
			if i > n - 1:
				break
			if l[i] % 2 != 0:
				ct2 += 1
			i += 1
		ans = max(even - ct1, odd - ct2)
		print(ans)
	else:
		print(-1)


t = int(input())
w = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	d = 1
	N_even = 0
	N_odd = 0
	while c <= n - 1:
		if a[c] % 2 == 1:
			N_even = N_even + 1
		c = c + 2
	while d <= n - 1:
		if a[d] % 2 == 0:
			N_odd = N_odd + 1
		d = d + 2
	if N_even == N_odd:
		w.append(N_even)
	else:
		w.append(-1)
for i in w:
	print(i)


from math import *

def r1(t):
	return t(input())

def r2(t):
	return [t(i) for i in input().split()]

def r3(t):
	return [t(i) for i in input()]
for _ in range(r1(int)):
	n = r1(int)
	a = r2(int)
	co = 0
	ce = 0
	cbo = 0
	cbe = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				cbe += 1
			else:
				cbo += 1
		if a[i] % 2 == 1:
			co += 1
		else:
			ce += 1
	if co != n // 2:
		print(-1)
	elif ce != (n + 1) // 2:
		print(-1)
	else:
		t = min(cbo, cbe)
		print(max(cbo, cbe))


t = int(input())
for ii in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	one = 0
	zeo = 0
	c = 0
	for (j, i) in enumerate(lis):
		if j % 2 != i % 2:
			c += 1
		if i % 2 == 0:
			zeo += 1
		else:
			one += 1
	if n % 2:
		if one + 1 == zeo:
			print(c // 2)
		else:
			print(-1)
	elif one == zeo:
		print(c // 2)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	io = 0
	ie = 0
	for i in range(n):
		if i % 2 != lst[i] % 2:
			if i % 2 == 0:
				io += 1
			else:
				ie += 1
	if io == ie:
		print(ie)
	else:
		print(-1)


def ea(l):
	o = 0
	e = 0
	for i in range(len(l)):
		if i % 2 == 0:
			if l[i] % 2 == 1:
				o = o + 1
		elif l[i] % 2 == 0:
			e = e + 1
	if o == e:
		print(o)
	else:
		print(-1)
	return
n = int(input())
for i in range(n):
	t = int(input())
	l = list(map(int, input().split(' ')))
	ea(l)


try:
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		cnt = 0
		cnt1 = 0
		for i in range(len(l)):
			if i % 2 == 0 and l[i] % 2 == 1:
				cnt += 1
			if i % 2 != 0 and l[i] % 2 == 0:
				cnt1 += 1
		if cnt1 == cnt:
			print(cnt)
		else:
			print('-1')
except:
	pass


import math
from decimal import Decimal
import heapq
import copy
import heapq
from collections import deque
from collections import defaultdict

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def da():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(n):
	tc = []
	ans = {}
	d = 2
	while d * d <= n:
		if n % d == 0:
			tc.append(d)
			n //= d
		else:
			d += 1
	if n > 1:
		tc.append(n)
	for i in tc:
		ans[i] = ans.get(i, 0) + 1
	return ans

def to_zero(n, s):
	lst = s[0]
	ans = []
	for i in range(n):
		if lst == s[i]:
			continue
		elif lst == '0':
			lst = '1'
			ans.append(i)
		else:
			lst = '0'
			ans.append(i)
	if lst == '1':
		ans.append(n)
	return ans
for _ in range(int(input())):
	(n, a) = na()
	ch = 0
	nech = 0
	chh = 0
	nechh = 0
	for i in a:
		if i % 2 == 0:
			ch += 1
		else:
			nech += 1
	if ch != n // 2 + n % 2 and nech != n // 2:
		print(-1)
	else:
		for i in range(n):
			if i % 2 == 0 and a[i] % 2 != 0:
				chh += 1
			elif i % 2 != 0 and a[i] % 2 == 0:
				nechh += 1
		d = min(chh, nechh)
		print(d)


case = int(input())
for loop in range(case):
	n = int(input())
	liste = list(map(int, input().split()))
	pair = 0
	impair = 0
	c = 0
	for i in range(n):
		if c == 0:
			c = 1
			if (liste[i] + 2) % 2 != 0:
				pair += 1
		else:
			c = 0
			if (liste[i] + 2) % 2 == 0:
				impair += 1
	if pair == impair:
		print(pair)
	else:
		print(-1)


import sys
caseCount = int(next(sys.stdin))

def solve(arr):
	n = len(arr)
	evencount = 0
	oddcount = 0
	for i in range(0, n, 2):
		if arr[i] % 2 != 0:
			evencount += 1
	for i in range(1, n, 2):
		if arr[i] % 2 != 1:
			oddcount += 1
	if evencount == oddcount:
		return evencount
	return -1
for i in range(caseCount):
	next(sys.stdin)
	x = next(sys.stdin)[:-1]
	nums = [int(a) for a in x.split(' ')]
	print(solve(nums))


t = int(input())
output = []
for i in range(t):
	n = int(input())
	arr = [int(num) for num in input().split()]
	(num_even, num_odd) = (0, 0)
	(num_even_wrong, num_odd_wrong) = (0, 0)
	for j in range(len(arr)):
		curr = arr[j]
		if curr % 2 == 0:
			num_even += 1
		else:
			num_odd += 1
		if j % 2 == 0:
			if curr % 2 == 1:
				num_odd_wrong += 1
		elif curr % 2 == 0:
			num_even_wrong += 1
	if len(arr) % 2 == 0:
		if num_even != num_odd:
			output.append(-1)
		else:
			output.append(num_even_wrong)
	elif num_even != num_odd + 1:
		output.append(-1)
	else:
		output.append(num_even_wrong)
for num in output:
	print(num)


t = int(input())
for i in range(t):
	n = int(input())
	err1 = err0 = 0
	a = list(map(int, input().split()))
	modA = []
	modI = []
	for i in range(n):
		modA.append(a[i] % 2)
	for i in range(n):
		modI.append(i % 2)
	for i in range(n):
		if modA[i] == modI[i]:
			continue
		elif modA[i] == 0 and modI[i] == 1:
			err0 += 1
		elif modA[i] == 1 and modI[i] == 0:
			err1 += 1
	if err1 == err0:
		print(err1)
	elif err1 != err0:
		print(-1)


t = int(input())
for i in range(1, t + 1):
	badn = 0
	badd = 0
	k = int(input())
	n = list(map(int, input().split()))
	for j in range(k):
		if n[j] % 2 != 0 and j % 2 != 0:
			continue
		elif n[j] % 2 == 0 and j % 2 == 0:
			continue
		elif n[j] % 2 == 0 and j % 2 != 0:
			badd += 1
		else:
			badn += 1
	if badd != badn:
		print(-1)
	else:
		print(badd)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ee = n // 2 + n % 2
	eo = n // 2
	(e, de) = (0, 0)
	o = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			de += 1
		if a[i] % 2 == 0:
			e += 1
		else:
			o += 1
	if e == ee and o == eo:
		print(de)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	opCount = 0
	das = -1
	broken = False
	for i in range(n):
		if i % 2 == a[i] % 2:
			continue
		else:
			for j in range(i + 1, n):
				if a[j] % 2 != j % 2:
					if a[j] % 2 == i % 2:
						(a[j], a[i]) = (a[i], a[j])
						opCount += 1
						break
					else:
						j += 1
				if j == n - 1 and a[i] % 2 != i % 2:
					broken = True
					break
			if broken:
				break
	for i in range(n):
		if i % 2 != a[i] % 2:
			das = -2
			break
	if das == -2:
		print(-1)
	else:
		print(opCount)


for _ in range(int(input())):
	l = int(input())
	nums = list(map(int, input().split()))
	dp = [0 for i in range(l)]
	coun = 0
	for i in range(l):
		if nums[i] % 2 == 1:
			dp[i] = 1
			coun += 1
	if coun != l // 2:
		print('-1')
	else:
		coun2 = 0
		for i in range(len(dp)):
			if dp[i] % 2 != i % 2:
				coun2 += 1
		print(coun2 // 2)


t = int(input())
i = 0
while i < t:
	e = 0
	o = 0
	n = int(input())
	l = []
	l = [int(num) for num in input().split()]
	for j in range(n):
		x = j - j // 2 * 2
		y = l[j] - l[j] // 2 * 2
		if x == 0 and y != 0:
			e = e + 1
		elif x != 0 and y == 0:
			o = o + 1
	if e == o:
		print(e)
		i = i + 1
	else:
		print('-1')
		i = i + 1


tests = int(input())
for t in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	err = [0, 0]
	for i in range(len(a)):
		r = i % 2
		if a[i] % 2 != r:
			err[r] += 1
	if err[0] == err[1]:
		print(err[0])
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	k = 0
	j = 0
	while x < n:
		if x % 2 == 0:
			if a[x] % 2 == 1:
				j = j + 1
		elif a[x] % 2 == 0:
			k = k + 1
		x = x + 1
	if j == k:
		print(j)
	else:
		print(-1)


test_cases = int(input())
for _ in range(test_cases):
	n = int(input())
	a = list(map(int, input().split(' ')))
	odd_index = {0: 0, 1: 0}
	even_index = {0: 0, 1: 0}
	index = [even_index, odd_index]
	for i in range(n):
		index[i % 2][a[i] % 2] += 1
	if odd_index[0] == even_index[1]:
		print(odd_index[0])
	else:
		print(-1)


def read_array():
	x = []
	x1 = []
	x = input()
	x = x.split(' ')
	for r in range(len(x)):
		x1.append(int(x[r]))
	return x1

def is_good(x):
	(med, med1) = (0, 0)
	for v in x:
		if v % 2 == 0:
			med += 1
		else:
			med1 += 1
	moves = 0
	for i in range(len(x)):
		if i % 2 == 0:
			med -= 1
		else:
			med1 -= 1
		if i % 2 == x[i] % 2:
			moves += 1
	if med1 != 0 and med != 0:
		return -1
	return int((len(x) - moves) / 2)
m = int(input())
res = []
for r in range(m):
	input()
	x = read_array()
	res.append(is_good(x))
for v in res:
	print(v)


testcases = int(input())
for testcase in range(testcases):
	n = int(input())
	temparr = input()
	temparr = temparr.split()
	arr = []
	for i in temparr:
		arr.append(int(i))
	num0 = 0
	num1 = 0
	for i in range(n):
		if i & 1 == 0 and arr[i] & 1 != 0:
			num0 += 1
		elif i & 1 == 1 and arr[i] & 1 != 1:
			num1 += 1
	if num1 != num0:
		print(-1)
	else:
		print(num1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(even, odd) = (0, 0)
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			even += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			odd += 1
	if abs(odd - even) == 0:
		print(min(even, odd))
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	ar = list(map(int, input().split()))
	li = [0] * n
	(c, d) = (0, 0)
	odd = n // 2
	arrayka1 = 0
	for i in range(1, n, 2):
		li[i] = 1
	for i in range(n):
		if ar[i] % 2 == 1:
			arrayka1 += 1
		ar[i] = ar[i] % 2
	for i in range(n):
		if li[i] == ar[i]:
			c += 1
		else:
			d += 1
	if c == n:
		print(0)
	elif d % 2 == 0 and arrayka1 == odd:
		print(d // 2)
	else:
		print(-1)
	t -= 1


import math
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	(oc, ec) = (0, 0)
	notinpos = 0
	for i in range(len(l)):
		if l[i] % 2 == 0:
			ec += 1
			if i % 2 != 0:
				notinpos += 1
		else:
			oc += 1
			if i % 2 == 0:
				notinpos += 1
	if n % 2 == 0:
		if oc != ec:
			print(-1)
		else:
			print(math.ceil(notinpos / 2))
	elif notinpos > 0 and (oc == 0 or ec == 0):
		print(-1)
	elif abs(oc - ec) > 1 or (oc > 0 and oc > ec):
		print(-1)
	else:
		print(math.ceil(notinpos / 2))


No_cases = int(input())
big_list = []
for i in range(No_cases):
	Array_size = int(input())
	big_list.append(list(map(int, list(input().split()))))
for i in big_list:
	one = [k % 2 for k in range(len(i))]
	two = [k % 2 for k in i]
	counter = 0
	if one.count(0) == two.count(0) or one.count(1) == two.count(1):
		for k in range(len(i)):
			if k % 2 == 0 and two[k] != 0:
				counter += 1
		print(counter)
	else:
		print(-1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(_) for _ in input().split()]
	(even, odd) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 == 0:
				pass
			else:
				even += 1
		elif a[i] % 2 == 1:
			pass
		else:
			odd += 1
	if n % 2 == 0:
		if even == odd:
			print(even)
		else:
			print(-1)
	elif even == odd:
		print(odd)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	L = input().split()
	L = [int(i) for i in L]
	status_index = []
	status_element = []
	status = []
	j = 0
	for i in L:
		status_index.append(j % 2)
		status_element.append(i % 2)
		if status_element[-1] == status_index[-1]:
			status.append(1)
		else:
			status.append(0)
		j += 1
	if sum(status_element) == sum(status_index):
		diff = n - sum(status)
		if diff % 2 == 0:
			print(diff // 2)
	else:
		print('-1')


t = int(input())
while t:
	t += -1
	n = int(input())
	a = list(map(int, input().split()))
	(e1, e2) = (0, 0)
	(o1, o2) = (0, 0)
	wrong = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			wrong -= -1
		if a[i] % 2:
			o1 -= -1
		if a[i] % 2 == 0:
			e1 -= -1
		if i % 2:
			o2 -= -1
		if i % 2 == 0:
			e2 -= -1
	if e1 == e2 and o1 == o2:
		print(wrong // 2)
	else:
		print(-1)


n = int(input())
for i in range(n):
	nu = int(input())
	(c1, c2) = (0, 0)
	l = list(map(int, input().split()))
	for i in range(nu):
		if i % 2 == 0 and l[i] % 2 != 0:
			c1 += 1
		elif i % 2 == 1 and l[i] % 2 != 1:
			c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)


test = int(input())
for t in range(test):
	number = int(input())
	a = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(number):
		if i % 2 == 0 and a[i] % 2 != 0:
			o += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			e += 1
	if e == o:
		print(e)
	else:
		print(-1)


n = int(input())
for i in range(n):
	k = int(input())
	l = list(map(int, input().split()))
	count = 0
	(even, odd) = (0, 0)
	for j in range(k):
		if j % 2 != l[j] % 2:
			count += 1
			if l[j] % 2 == 0:
				even += 1
			else:
				odd += 1
	if count > 0:
		if odd == even:
			print(odd)
		else:
			print('-1')
	else:
		print('0')


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	par = 0
	impar = 0
	diff = 0
	for i in range(n):
		pos = i % 2
		val = arr[i] % 2
		if val == 0:
			par += 1
		else:
			impar += 1
		if pos != val:
			diff += 1
	if par == n // 2 + n % 2 and impar == n // 2:
		print(diff // 2)
	else:
		print(-1)


def func(arr, n):
	count = 0
	o_c = len(list(filter(lambda x: x % 2 != 0, arr)))
	e_c = len(list(filter(lambda x: x % 2 == 0, arr)))
	if o_c > e_c or e_c > o_c + 1:
		return -1
	else:
		for c in range(0, n, 2):
			if arr[c] % 2 != 0:
				count += 1
		for d in range(1, n, 2):
			if arr[d] % 2 == 0:
				count += 1
		return count // 2
for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(func(arr, n))


t = int(input())
for idx in range(t):
	n = int(input())
	arr = map(int, input().strip().split(' '))
	corr_zero_cnt = 0
	incorr_zero_cnt = 0
	corr_one_cnt = 0
	incorr_one_cnt = 0
	for (jdx, val) in zip(range(n), arr):
		if jdx % 2 == 0:
			if val % 2 == 0:
				corr_zero_cnt += 1
			else:
				incorr_zero_cnt += 1
		elif val % 2 == 0:
			incorr_one_cnt += 1
		else:
			corr_one_cnt += 1
	n -= corr_one_cnt + corr_zero_cnt
	if incorr_zero_cnt != incorr_one_cnt:
		print(-1)
	else:
		print(incorr_one_cnt)


for i in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	dict = []
	for j in range(len(a)):
		if a[j] % 2 != j % 2:
			dict.append(a[j])
	nec = 0
	chet = 0
	for j in dict:
		if j % 2 == 0:
			chet += 1
		else:
			nec += 1
	if nec == chet:
		print(nec)
		continue
	else:
		print(-1)


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	s = 0
	for i in range(n):
		a[i] = a[i] % 2
		k = a[i] - i % 2
		l.append(k)
		s = s + k
	if s != 0:
		print(-1)
	else:
		p = l.count(-1)
		print(p)


t = int(input())
for _ in range(t):
	(a, b, even, odd, co) = (0, 0, 0, 0, 0)
	n = int(input())
	if n % 2 == 0:
		even = int(n / 2)
		odd = int(n / 2)
	else:
		even = int(n / 2 + 1)
		odd = int(n / 2)
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i] % 2 == 0:
			a += 1
		else:
			b += 1
	if a == even and odd == b:
		i = 1
		while i < n:
			if l[i] % 2 == 0:
				co += 1
			i += 2
		print(co)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	arr = [int(i) for i in list(input().split())]
	c_w_o = 0
	c_w_e = 0
	for i in range(n):
		if arr[i] % 2 == i % 2:
			continue
		if i % 2 == 0:
			c_w_e += 1
		else:
			c_w_o += 1
	if c_w_e == c_w_o:
		print(c_w_o)
	else:
		print(-1)


t = int(input())
while t != 0:
	n = int(input())
	list1 = list(map(int, input().split()))
	(z, o) = (0, 0)
	if n % 2 == 0:
		(z, o) = (n // 2, n // 2)
	else:
		(z, o) = ((n + 1) // 2, n // 2)
	i = 0
	n_z = 0
	n_o = 0
	not_match = 0
	while i < n:
		if list1[i] % 2 == 0:
			n_z += 1
			if i % 2 != 0:
				not_match += 1
		else:
			n_o += 1
			if i % 2 == 0:
				not_match += 1
		i += 1
	if n % 2 == 0:
		if n_o == n_z:
			if not_match % 2 == 0:
				print(not_match // 2)
			else:
				print(-1)
		else:
			print(-1)
	elif n_o == n_z - 1:
		if not_match % 2 == 0:
			print(not_match // 2)
		else:
			print(-1)
	else:
		print(-1)
	t -= 1


def f(list_of_line):
	l = len(list_of_line)
	even = 0
	odd = 0
	for i in list_of_line:
		if i % 2 == 0:
			even += 1
		else:
			odd += 1
	if odd == l // 2:
		return 1
	else:
		return 0

def ff(list_of_line):
	ch = 0
	for i in range(0, len(list_of_line)):
		if i % 2 == 0 and list_of_line[i] % 2 == 0:
			continue
		elif i % 2 != 0 and list_of_line[i] % 2 != 0:
			continue
		else:
			ch += 1
	ch //= 2
	return ch
count = int(input())
list_of_answer = []
for i in range(0, count):
	count_of_list = int(input())
	line = input()
	list_of_line = line.split()
	list_of_line = list(map(int, list_of_line))
	re = f(list_of_line)
	if re == 0:
		list_of_answer.append(-1)
	else:
		c = ff(list_of_line)
		list_of_answer.append(c)
for i in list_of_answer:
	print(i)


from functools import reduce
import collections
import math
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(delimiter=' '):
		return input().split(delimiter)

	@staticmethod
	def list_int(delimiter=' '):
		return list(map(int, input().split(delimiter)))

def main():
	t = Read.int()
	for _ in range(t):
		n = Read.int()
		a = Read.list_int()
		c = 0
		ne = 0
		for i in range(n):
			if a[i] % 2 != i % 2:
				if a[i] % 2 == 1:
					ne += 1
				else:
					c += 1
		if c == ne:
			print(c)
		else:
			print(-1)
main()


t = int(input())
for _ in range(t):
	x = int(input())
	arr = list(map(int, input().split()))
	newarr = [0] * x
	for i in range(x):
		if arr[i] % 2 != i % 2:
			if i % 2 == 0:
				newarr[i] = 2
			else:
				newarr[i] = 1
	count1 = newarr.count(1)
	count2 = newarr.count(2)
	if count1 == count2:
		print(count1)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	nch = 0
	ch = 0
	for i in range(n):
		if a[i] % 2 == 0 and i % 2 == 1:
			ch += 1
		elif a[i] % 2 == 1 and i % 2 == 0:
			nch += 1
	if nch != ch:
		print(-1)
	else:
		print(ch)


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = list(map(int, input().split()))
	bad1 = 0
	bad0 = 0
	for i in range(n):
		if s[i] % 2 == i % 2:
			continue
		if s[i] % 2 == 0:
			bad0 += 1
		else:
			bad1 += 1
	if bad0 == 0 and bad1 == 0:
		print(0)
		continue
	if bad0 == bad1:
		print(bad0)
	if bad0 != bad1:
		print(-1)


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(e1, e2, o1, o2) = (0, 0, 0, 0)
	d = 0
	for i in range(n):
		if i % 2 == 0:
			e1 += 1
		else:
			o1 += 1
		if a[i] % 2 == 0:
			e2 += 1
		else:
			o2 += 1
		if i % 2 != a[i] % 2:
			d += 1
	if e1 == e2 and o1 == o2:
		print(d // 2)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	bad = good = 0
	for i in range(n):
		if i % 2 == 0 and lis[i] % 2 != 0:
			bad += 1
		if i % 2 != 0 and lis[i] % 2 == 0:
			good += 1
	if good == bad:
		print(good)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	s = [int(i) for i in input().split()]
	r = n // 2
	l = n - r
	l1 = 0
	for i in range(len(s)):
		if s[i] % 2 == 0:
			l1 += 1
	if l != l1:
		print(-1)
		continue
	k = 0
	for i in range(len(s)):
		if i % 2 == 0 and s[i] % 2 != 0:
			k += 1
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(s) for s in input().split()]
	i = 0
	ch = 0
	ne = 0
	for el in a:
		if i % 2 == 0 and el % 2 != 0:
			ne += 1
		if i % 2 != 0 and el % 2 == 0:
			ch += 1
		i += 1
	if ne == ch:
		print(ne)
	else:
		print(-1)


T = int(input())
for _ in range(T):
	N = int(input())
	L = list(map(lambda x: int(x) % 2, input().split()))
	odd = 0
	even = 0
	for (i, l) in enumerate(L):
		if i % 2 != l % 2:
			if i % 2 == 0:
				even += 1
			else:
				odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		N = int(input())
		A = map(int, input().split())
		num_i = [0, 0]
		num_a = [0, 0]
		for (i, a) in enumerate(A):
			if i % 2 != a % 2:
				num_i[i % 2] += 1
				num_a[a % 2] += 1
		if num_i[0] != num_a[0] or num_i[1] != num_a[1]:
			print(-1)
		else:
			print(num_i[0])
main()


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	for i in range(n):
		if i % 2 == 0 and arr[i] % 2 != 0:
			c1 += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)


for t in range(int(input())):
	fg = int(input())
	c = 0
	f = 0
	kl = 0
	for i in input().split():
		k = int(i)
		if k % 2 == kl % 2:
			kl += 1
		else:
			if k % 2 == 1:
				c += 1
			else:
				f += 1
			kl += 1
	if c != f:
		print(-1)
	else:
		print(c)


from sys import stdin

def r():
	return stdin.readline().strip()

def r_t(tp):
	return map(tp, r().strip().split())

def r_a(tp):
	return list(r_t(tp))

def parity_cnt(n, A):
	(odds, evens) = (0, 0)
	for x in A:
		if x & 1:
			odds += 1
		else:
			evens += 1
	return (evens, odds)

def solve(n, A):
	(ev_cnt, od_cnt) = parity_cnt(n, A)
	ans = -1
	if n % 2 == 0 and ev_cnt == od_cnt:
		bad = 0
		for i in range(n):
			if i % 2 != A[i] % 2:
				bad += 1
		ans = bad // 2
	elif n & 1 and ev_cnt - 1 == od_cnt:
		bad = 0
		for i in range(n):
			if i % 2 != A[i] % 2:
				bad += 1
		ans = bad // 2
	return ans

def main():
	cases = int(r())
	for case in range(cases):
		n = int(r())
		A = list(r_t(int))
		print(solve(n, A))
main()


n = int(input())
for i in range(n):
	l = int(input())
	arr = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	for i in range(l):
		if i % 2 == 0 and arr[i] % 2 != 0:
			count1 += 1
		elif i % 2 != 0 and arr[i] % 2 == 0:
			count2 += 1
	if count1 != count2:
		ans = -1
	else:
		ans = count1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	count = 0
	l1 = []
	l2 = []
	for i in range(n):
		if i % 2 == a[i] % 2:
			count += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			l1.append(a[i])
		else:
			l2.append(a[i])
	if count == n:
		print(0)
	elif len(l1) != len(l2):
		print(-1)
	else:
		print(len(l1))


def parityCount(lst):
	a = [0, 0]
	for i in range(len(lst)):
		if i % 2 == lst[i] % 2:
			continue
		a[i % 2] += 1
	if a[0] == a[1]:
		return a[0]
	return -1

def main():
	for _ in range(int(input())):
		n = int(input())
		lst = list(map(int, input().split()))
		print(parityCount(lst))
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	(e, o) = (0, 0)
	(ep, op) = (0, 0)
	for i in range(n):
		if i % 2 != a[i] % 2:
			c += 1
			if a[i] % 2 == 0:
				e += 1
			else:
				o += 1
	if c == 0:
		print(0)
	elif e != o:
		print(-1)
	else:
		print(c // 2)


def solve():
	n = int(input())
	A = list(map(int, input().split()))
	pos = []
	even_pos = 0
	odd_pos = 0
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 != A[i] % 2:
			pos.append(i)
			if i % 2 == 0:
				even_pos += 1
			else:
				odd_pos += 1
			if A[i] % 2 == 0:
				even += 1
			else:
				odd += 1
	if len(pos) == 0:
		print(0)
	elif len(pos) == 1 or even != odd:
		print(-1)
	else:
		print(even)
t = int(input())
while t > 0:
	t -= 1
	solve()


T = int(input())
ans = []
for t in range(T):
	n = int(input())
	lst = str.split(input())
	lst = [int(nmb) for nmb in lst]
	oddcnt = 0
	evencnt = 0
	for i in range(n):
		if lst[i] % 2 == 0 and i % 2 != 0:
			evencnt += 1
		elif lst[i] % 2 != 0 and i % 2 == 0:
			oddcnt += 1
	if evencnt == oddcnt:
		ans.append(evencnt)
	else:
		ans.append(-1)
print(*ans, sep='\n')


for _ in range(int(input())):
	r = int(input())
	s = list(map(int, input().split()))
	t = []
	count = 0
	zeroCount = 0
	oneCount = 0
	for i in range(r):
		if s[i] % 2 == 0:
			t.append(0)
		elif s[i] % 2 == 1:
			t.append(1)
	for i in range(len(t)):
		if i % 2 == 0:
			if t[i] != 0:
				count += 1
				zeroCount += 1
		elif t[i] != 1:
			count += 1
			oneCount += 1
	if count % 2 == 0:
		if zeroCount == oneCount:
			print(count // 2)
		else:
			print(-1)
	else:
		print(-1)


N = int(input())
for i in range(N):
	L = int(input())
	A = list(map(int, input().split()))
	(e, o) = (0, 0)
	for j in range(L):
		if j % 2 == 1 != A[j] % 2:
			o += 1
		elif j % 2 == 0 != A[j] % 2:
			e += 1
	if e == o:
		print(e)
	else:
		print(-1)


def count_odd(l):
	va = 0
	for i in l:
		if i % 2 != 0:
			va += 1
	return va

def count_even(l):
	va1 = 0
	for i in l:
		if i % 2 == 0:
			va1 += 1
	return va1
n = int(input())
for i in range(n):
	t = int(input())
	l = [int(x) for x in input().split()]
	ev = 0
	odd = 0
	for i in range(t):
		if i % 2 == 0 and l[i] % 2 != 0:
			ev += 1
		elif i % 2 != 0 and l[i] % 2 == 0:
			odd += 1
	if ev == odd:
		print(ev)
	else:
		print(-1)


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	outevens = 0
	outodds = 0
	evens = 0
	odds = 0
	for x in range(n):
		if a[x] % 2 == 0:
			evens += 1
			if x % 2 != 0:
				outevens += 1
		else:
			odds += 1
			if x % 2 == 0:
				outodds += 1
	if n % 2 == 1 and evens != odds + 1:
		stdout.write('-1\n')
	elif n % 2 == 0 and evens != odds:
		stdout.write('-1\n')
	else:
		stdout.write(str(outevens) + '\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	isBad = 0
	for i in range(n):
		if i & 1 and a[i] % 2 == 0 or (i % 2 == 0 and a[i] & 1):
			isBad = 1
	if not isBad:
		print(0)
		continue
	wrongOdd = 0
	wrongEven = 0
	for i in range(n):
		if i % 2 == 0 and a[i] & 1:
			wrongEven += 1
		elif i & 1 and a[i] % 2 == 0:
			wrongOdd += 1
	if wrongEven != wrongOdd:
		print(-1)
	else:
		print(wrongEven)


def main():
	testCases = int(input())
	for _ in range(testCases):
		(n, arr) = (int(input()), list(map(int, input().rstrip().split())))
		misplaced = {'odd': [], 'even': []}
		for i in range(n):
			if i % 2 != arr[i] % 2:
				if i % 2 == 0:
					misplaced['odd'].append(arr[i])
				else:
					misplaced['even'].append(arr[i])
		if len(misplaced['odd']) != len(misplaced['even']):
			print(-1)
		else:
			print(len(misplaced['odd']))
main()


def iseven(x):
	if x % 2 == 0:
		return True

def isodd(y):
	if y % 2 != 0:
		return True
for i in range(int(input())):
	n = int(input())
	count = 0
	count2 = 0
	count3 = 0
	l = [int(x) for x in input().split()]
	for i in range(len(l)):
		if iseven(i) and iseven(l[i]):
			pass
		elif isodd(i) and isodd(l[i]):
			pass
		else:
			count2 += 1
			if iseven(i):
				for j in range(i + 1, len(l)):
					if iseven(l[j]):
						if isodd(j):
							temp = l[i]
							l[i] = l[j]
							l[j] = temp
							count += 1
							break
			else:
				for j in range(i + 1, len(l)):
					if isodd(l[j]):
						if iseven(j):
							temp = l[i]
							l[i] = l[j]
							l[j] = temp
							count += 1
							break
	if count2 > count:
		print(-1)
	else:
		print(count)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	n1 = 0
	s = 0
	for j in range(len(l)):
		if l[j] % 2 == 1 and j % 2 == 1 or (l[j] % 2 == 0 and j % 2 == 0):
			n1 += 0
		else:
			n1 += 1
	for j in range(len(l)):
		if l[j] % 2 == 0:
			s += 1
	s1 = n // 2
	if n % 2 == 1:
		s1 += 1
	s1 += 0
	if s == s1:
		print(n1 // 2)
	else:
		print(-1)


def check(l, n):
	z = []
	s = []
	for i in range(0, n, 2):
		if l[i] % 2 == 0:
			pass
		else:
			s.append(i)
	for j in range(1, n, 2):
		if l[j] % 2 == 0:
			z.append(j)
	if z == [] and s == []:
		print(0)
	elif len(z) != len(s):
		print(-1)
	else:
		print(len(s))
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	check(l, n)


t = int(input())

def solve(b):
	(oddIndex, evenIndex) = (0, 0)
	(oddNumber, evenNumber) = (0, 0)
	for i in range(len(b)):
		indexMod = i % 2
		numberMod = b[i] % 2
		if indexMod != numberMod:
			if indexMod == 0:
				evenIndex += 1
			else:
				oddIndex += 1
	if evenIndex == oddIndex:
		return evenIndex
	else:
		return -1
while t > 0:
	b = input()
	a = [int(x) for x in input().split()]
	print(solve(a))
	t -= 1


from copy import copy

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	odd = 0
	for i in range(n):
		odd += a[i] % 2 == 1
	even = n - odd
	if even == n // 2 + n % 2 and odd == n // 2:
		cnt = 0
		for i in range(n):
			cnt += a[i] % 2 != i % 2
		print(cnt // 2)
	else:
		print(-1)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	x = int(input())
	y = list(map(int, input().split()))
	count_odd_num = 0
	count_even_num = 0
	if len(y) % 2 != 0:
		count_even_ind = int(len(y) / 2) + 1
		count_odd_ind = int(len(y) / 2)
	else:
		count_even_ind = int(len(y) / 2)
		count_odd_ind = int(len(y) / 2)
	for i in y:
		if i % 2 == 0:
			count_even_num += 1
		else:
			count_odd_num += 1
	i = 0
	count = 0
	if count_odd_ind == count_odd_num and count_even_ind == count_even_num:
		while i < len(y):
			if y[i] % 2 == i % 2:
				count += 1
			i += 1
		print((len(y) - count) // 2)
	else:
		print(-1)


t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	odd_wrong = 0
	even_wrong = 0
	for (i, x) in enumerate(a):
		if x % 2 == 0 and i % 2 == 1:
			even_wrong += 1
		if x % 2 == 1 and i % 2 == 0:
			odd_wrong += 1
	if odd_wrong == even_wrong:
		print(odd_wrong)
	else:
		print(-1)


t = int(input())
for t1 in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	odd = 0
	even = 0
	c = 0
	for i in range(0, n):
		if l[i] % 2 == 0:
			even += 1
		if l[i] % 2 == 1:
			odd += 1
		if i % 2 == 0:
			if l[i] % 2 == 1:
				c = c + 1
		elif i % 2 == 1:
			if l[i] % 2 == 0:
				c = c + 1
	if c == 0:
		print(0)
	elif n % 2 == 0:
		if n // 2 != even:
			print(-1)
		else:
			print(c // 2)
	elif (n + 1) // 2 != even:
		print(-1)
	else:
		print(c // 2)


I = input
for _ in range(int(I())):
	n = int(input())
	a = list(map(int, I().split()))
	evp = 0
	odp = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 != 0:
				evp += 1
		elif a[i] % 2 == 0:
			odp += 1
	if evp == odp:
		print(evp)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	count1 = 0
	for i in range(len(l)):
		if i & 1 == 1:
			if l[i] & 1 != 1:
				count += 1
		elif l[i] & 1 == 1:
			count1 += 1
	counter = min(count, count1)
	count = count - counter
	count1 = count1 - counter
	if count == 0 and count1 == 0:
		print(counter)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	(e, o) = ([], [])
	cnt = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if a[i] % 2 == 1:
				o.append(i)
			else:
				e.append(i)
		if len(o) > 0 and len(e) > 0:
			(a[o[0]], a[e[0]]) = (a[e[0]], a[o[0]])
			cnt += 1
			e.pop(0)
			o.pop(0)
	if len(o) == 0 and len(e) == 0:
		print(cnt)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	str = input()
	list = str.split()
	even = 0
	odd = 0
	for num in list:
		if int(num) % 2 == 1:
			odd = odd + 1
		else:
			even = even + 1
	if odd == even - len(list) % 2:
		ctr = 0
		j = 0
		while j < len(list):
			ctr += (j % 2 + int(list[j]) % 2) % 2
			j = j + 1
		print(int(ctr / 2))
	else:
		print(-1)


for x in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	a = 0
	b = 0
	for i in range(n):
		if i % 2 == 0 and m[i] % 2 != 0:
			a += 1
		if i % 2 != 0 and m[i] % 2 == 0:
			b += 1
	if a == b:
		print(a)
	else:
		print(-1)


t = int(input())
for case in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	evenWrong = oddWrong = 0
	for i in range(n):
		if arr[i] % 2 == 0 and i % 2 == 1:
			evenWrong += 1
		elif arr[i] % 2 == 1 and i % 2 == 0:
			oddWrong += 1
	if evenWrong != oddWrong:
		print('-1')
	else:
		print(evenWrong)


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	A = [a % 2 for a in A]
	e = 0
	o = 0
	for a in A:
		if a == 0:
			e += 1
		else:
			o += 1
	if n % 2 == 0:
		if e != n // 2:
			print(-1)
			continue
	elif e != n // 2 + 1:
		print(-1)
		continue
	ans = 0
	for (i, a) in enumerate(A):
		if a != i % 2:
			ans += 1
	print(ans // 2)


import sys
cont = sys.stdin.readlines()
cont = [i.strip('\n').split() for i in cont]
numTests = int(cont.pop(0)[0])
nc = []
for i in range(numTests):
	nc.append(cont[:2])
	cont = cont[2:]
for l in nc:
	lenn = int(l[0][0])
	t = [int(j) for j in l[1]]
	numEven = len([i for i in t if i % 2 == 0])
	if lenn % 2 == 0:
		if numEven == lenn / 2:
			numIncorrect = 0
			for (ind, i) in enumerate(t):
				if i % 2 != ind % 2:
					numIncorrect += 1
			print(numIncorrect // 2)
		else:
			print(-1)
	elif numEven == lenn - numEven + 1:
		numIncorrect = 0
		for (ind, i) in enumerate(t):
			if i % 2 != ind % 2:
				numIncorrect += 1
		print(numIncorrect // 2)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	a = [int(num) for num in input().split()]
	(e_e, o_e) = (0, 0)
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2 == 0:
				e_e += 1
			else:
				o_e += 1
	if e_e == o_e:
		print(e_e)
	else:
		print(-1)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	e = 0
	o = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			e = e + 1
		elif i % 2 == 1 and a[i] % 2 == 0:
			o = o + 1
	if e == o:
		print(e)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	ox = 0
	ex = 0
	for i in range(n):
		if i % 2 == 0:
			if lis[i] % 2 == 1:
				ex = ex + 1
			else:
				continue
		if i % 2 == 1:
			if lis[i] % 2 == 0:
				ox = ox + 1
			else:
				continue
	if ex == ox:
		print(ex)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = input()
	s = list(map(int, input().split()))
	mal_impar = 0
	mal_par = 0
	for i in range(len(s)):
		if i % 2 != s[i] % 2:
			if i % 2:
				mal_impar += 1
			else:
				mal_par += 1
	if mal_impar == 0 and mal_par == 0:
		print(0)
	elif mal_impar != mal_par:
		print(-1)
	else:
		print(mal_par)


t = int(input())
for jack in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(od, ev) = (0, 0)
	for i in range(n):
		if a[i] % 2 != i % 2:
			if i % 2 == 0:
				ev += 1
			else:
				od += 1
	if od == ev:
		print(od)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	o_err = 0
	e_err = 0
	for j in range(n):
		if j % 2 == 0:
			if a[j] % 2 == 1:
				e_err += 1
		elif a[j] % 2 == 0:
			o_err += 1
	if o_err != e_err:
		print('-1')
	else:
		print(o_err)


n = int(input())
for j in range(n):
	n = int(input())
	A = list(map(int, input().split()))
	countevenod = 0
	countodeven = 0
	for i in range(n):
		if A[i] % 2 == i % 2:
			A[i] = -1
	for h in range(n):
		if A[h] != -1:
			if A[h] % 2 == 0:
				if h % 2 != 0:
					countevenod += 1
			elif h % 2 == 0:
				countodeven += 1
	if countevenod == countodeven:
		print(countevenod)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	evensnotok = 0
	oddsnotok = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % 2 == 1:
				evensnotok += 1
		elif a[i] % 2 == 0:
			oddsnotok += 1
	if evensnotok != oddsnotok:
		print(-1)
	else:
		print(evensnotok)


for t in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	o = 0
	e = 0
	for i in range(len(li)):
		if i % 2 != li[i] % 2:
			if li[i] % 2 == 1:
				o += 1
			else:
				e += 1
	if e == o:
		print(e)
	else:
		print(-1)


import string
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	counteven = 0
	countodd = 0
	for i in range(n):
		if i % 2 != a[i] % 2:
			if i % 2 == 1:
				counteven += 1
			else:
				countodd += 1
	if counteven != countodd:
		print(-1)
	else:
		print(counteven)


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	n = int(sys.stdin.readline().rstrip())
	a = list(map(int, sys.stdin.readline().rstrip().split()))
	cnt0 = 0
	cnt1 = 0
	for i in range(n):
		a[i] = a[i] % 2
		if a[i] == 0:
			cnt0 += 1
		elif a[i] == 1:
			cnt1 += 1
	if n % 2 == 0 and cnt0 != cnt1 or (n % 2 == 1 and cnt0 != cnt1 + 1):
		print(-1)
		continue
	else:
		re = 0
		for i in range(n):
			if a[i] != i % 2:
				re += 1
		print(int(re / 2))


t = int(input())
for _ in range(t):
	n = int(input())
	aa = list(map(int, input().split()))
	bb = []
	cc = 0
	for i in aa:
		if cc == 0:
			cc = 1
			if i % 2 == 0:
				bb.append(0)
			else:
				bb.append('E')
		else:
			cc = 0
			if i % 2 != 0:
				bb.append(0)
			else:
				bb.append('O')
	if bb.count('E') != bb.count('O'):
		print(-1)
	else:
		print(bb.count('E'))


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		notMatched = [True if i % 2 != a[i] % 2 else False for i in range(n)]
		num = 0
		for i in range(n):
			if notMatched[i]:
				for j in range(i + 1, n):
					if notMatched[j] and i % 2 == a[j] % 2 and (j % 2 == a[i] % 2):
						notMatched[i] = False
						notMatched[j] = False
						num += 1
						break
				if notMatched[i]:
					num = -1
					break
		print(num)
main()


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = LIST()
	cnt = [0] * 2
	for i in range(N):
		if i % 2 != A[i] % 2:
			cnt[i % 2] += 1
	if cnt[0] != cnt[1]:
		print(-1)
	else:
		ans = cnt[0]
		print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	even = []
	odd = []
	count = 0
	for i in range(len(arr)):
		if i % 2 == 0:
			if arr[i] % 2 == 0:
				continue
			elif len(odd) == 0:
				even.append(i)
			else:
				count += 1
				temp = arr[odd[0]]
				arr[odd[0]] = arr[i]
				arr[i] = temp
				odd.pop(0)
		elif arr[i] % 2 != 0:
			continue
		elif len(even) == 0:
			odd.append(i)
		else:
			count += 1
			temp = arr[even[0]]
			arr[even[0]] = arr[i]
			arr[i] = temp
			even.pop(0)
	if len(even) == 0 and len(odd) == 0:
		print(count)
	else:
		print(-1)


def solve(ar, n):
	(ne, no, ns) = (0, 0, 0)
	for i in range(n):
		if ar[i] % 2 == 0:
			ne += 1
		else:
			no += 1
		if ar[i] % 2 != i % 2:
			ns += 1
	if ns % 2 == 0 and abs(ne - no) <= 1:
		return ns // 2
	else:
		return -1
for t in range(int(input())):
	n = int(input())
	ar = [int(s) for s in input().split()]
	print(solve(ar, n))


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	cntp = 0
	cnti = 0
	for i in range(n):
		if a[i] % 2 != i % 2:
			if i % 2:
				cnti += 1
			else:
				cntp += 1
	if cnti != cntp:
		print(-1)
	else:
		print(cnti)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		l = list(map(int, input().split()))
		op = ep = 0
		for i in range(n):
			if i & 1 == 0 and l[i] & 1 != 0:
				op += 1
			elif i & 1 == 1 and l[i] & 1 != 1:
				ep += 1
		if ep != op:
			print(-1)
		elif ep == 0 and op == 0:
			print(0)
		else:
			print(ep)
main()


for i in range(int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	for i in range(x):
		k = i % 2
		m = l[i] % 2
		if k == 0 and m != 0:
			c1 += 1
		if k != 0 and m == 0:
			c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ow = ew = 0
	for i in range(n):
		if i % 2 == 0 and a[i] % 2 != 0:
			ew += 1
		elif i % 2 != 0 and a[i] % 2 == 0:
			ow += 1
	print(-1 if ew != ow else ew)


t = int(input())
while t != 0:
	n = int(input())
	arr = []
	arr = [int(x) for x in input().split()]
	count = 0
	b = []
	c = []
	for i in range(len(arr)):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0 and arr[i] % 2 != 0:
				b.append(i)
			else:
				c.append(i)
			count += 1
	if len(b) == len(c):
		print(len(b))
	else:
		print(-1)
	t = t - 1


for z in range(int(input())):
	y = int(input())
	a = list(map(int, input().split()))
	p = []
	for i in range(y):
		if i % 2 == 0:
			if a[i] % 2 == 0:
				p.append(0)
			else:
				p.append('r')
		elif a[i] % 2 != 0:
			p.append(0)
		else:
			p.append('u')
	s1 = p.count('r')
	s2 = p.count('u')
	if s1 != s2:
		print(-1)
	else:
		print(s1)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	n = ri()
	A = rl()
	odds = n // 2
	evens = n - odds
	oe = 0
	eo = 0
	for (i, a) in enumerate(A):
		if i % 2 == a % 2:
			continue
		elif i % 2 == 0:
			eo += 1
		else:
			oe += 1
	if oe != eo:
		print(-1)
	else:
		print(oe)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


from sys import stdin, stdout
q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, stdin.readline().split()))
	cnt = 0
	even = 0
	odd = 0
	for i in range(n):
		if i % 2 == a[i] % 2:
			continue
		else:
			if a[i] % 2 == 0:
				even += 1
			else:
				odd += 1
			cnt += 1
	if even == odd:
		print(even)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [0] * n
	str_in = input().split(' ')
	for i in range(n):
		arr[i] = int(str_in[i])
	(ptr1, ptr2) = (0, 1)
	(cnt1, cnt2) = (0, 0)
	while ptr1 < n:
		if arr[ptr1] % 2 != 0:
			cnt1 += 1
		ptr1 += 2
	while ptr2 < n:
		if arr[ptr2] % 2 != 1:
			cnt2 += 1
		ptr2 += 2
	if cnt1 == cnt2:
		print(cnt1)
	else:
		print(-1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	even_in_odd = 0
	odd_in_even = 0
	for (index, i) in enumerate(a):
		if index % 2 == 1 and i % 2 == 0:
			even_in_odd += 1
		if index % 2 == 0 and i % 2 == 1:
			odd_in_even += 1
	if even_in_odd != odd_in_even:
		print(-1)
	else:
		print(even_in_odd)


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	(e1, o1) = (0, 0)
	c1 = 0
	for i in range(0, len(arr)):
		if i % 2 != arr[i] % 2:
			c1 += 1
		if arr[i] % 2 == 0:
			e1 += 1
		else:
			o1 += 1
	if n % 2 != 0 and (e1 != n // 2 + 1 or o1 != n // 2):
		print(-1)
		return
	elif n % 2 == 0 and e1 != o1:
		print(-1)
		return
	print(c1 // 2)
t = int(input())
for i in range(t):
	solve()


def horosh(mas):
	kol1 = 0
	kol2 = 0
	for i in range(0, len(mas)):
		if int(mas[i]) % 2 == 0:
			kol1 += 1
		else:
			kol2 += 1
	if len(mas) % 2 == 0:
		if kol1 == len(mas) // 2 and kol2 == len(mas) // 2:
			kol = 0
			for j in range(0, len(mas)):
				if int(mas[j]) % 2 != j % 2:
					kol += 1
			return kol // 2
		else:
			return -1
	elif kol1 == len(mas) // 2 + 1 and kol2 == len(mas) // 2:
		kol = 0
		for j in range(0, len(mas)):
			if int(mas[j]) % 2 != j % 2:
				kol += 1
		return kol // 2
	else:
		return -1

def gotov(mass):
	k = 0
	for i in range(0, len(mass)):
		if int(mass[i]) % 2 == int(i) % 2:
			k += 1
	if k == len(mass):
		return True
t = int(input())
massive = list()
for i in range(0, t):
	n = int(input())
	mas = input().split()
	if gotov(mas):
		massive.append(0)
	else:
		massive.append(horosh(mas))
for i in massive:
	print(i)


x = int(input())
for q in range(x):
	n = int(input())
	l = list(map(int, input().split()))
	f = 'd'
	f1 = 'd'
	ch = 0
	nch = 0
	chwrong = 0
	nchwrong = 0
	for i in range(n):
		if l[i] % 2 == 0:
			ch += 1
		else:
			nch += 1
		if i % 2 != l[i] % 2:
			f = 'u'
			if l[i] % 2 == 0:
				chwrong += 1
			else:
				nchwrong += 1
	if f == 'u':
		if n % 2 == 0 and ch == nch or (n % 2 != 0 and ch - 1 == nch):
			if chwrong == nchwrong:
				ans = chwrong
			else:
				f1 = 'u'
		else:
			f1 = 'u'
	if f == 'd':
		print(0)
	elif f1 == 'u':
		print(-1)
	else:
		print(ans)


def main():
	t = int(input())
	while t > 0:
		t = t - 1
		n = int(input())
		a = list(map(int, input('').strip().split()))
		oddcount = 0
		evencount = 0
		wrongodd = 0
		i = 0
		while i < n:
			if a[i] % 2 == 0:
				evencount += 1
			elif a[i] % 2 != 0:
				oddcount += 1
				if i % 2 == 0:
					wrongodd += 1
			i = i + 1
		if n == 1:
			if oddcount == 1:
				print('-1')
			else:
				print('0')
		elif n % 2 == 0:
			if oddcount != evencount:
				print('-1')
			else:
				print(wrongodd)
		elif n % 2 != 0 and oddcount - evencount >= 1:
			print('-1')
		elif n % 2 != 0 and evencount - oddcount > 1:
			print(-1)
		else:
			print(wrongodd)
main()


t = int(input())
for i in range(t):
	n = int(input())
	array = tuple(map(int, input().split()))
	even = odd = 0
	for k in range(n):
		if k % 2 != array[k] % 2:
			if k % 2 == 0:
				even += 1
			else:
				odd += 1
	if odd == even:
		print(odd)
	else:
		print(-1)


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	oddeven = [0, 0]
	for i in range(n):
		if i % 2 == arr[i] % 2:
			continue
		oddeven[i % 2] += 1
	if oddeven[0] == oddeven[1]:
		return oddeven[0]
	return -1
for _ in range(int(input())):
	print(solve())


cases = int(input())
for case in range(cases):
	length = int(input())
	nums = list(map(int, input().split()))
	mis_parity_0 = 0
	mis_parity_1 = 0
	for index in range(length):
		if index % 2 == nums[index] % 2:
			continue
		elif index % 2 == 0:
			mis_parity_1 += 1
		else:
			mis_parity_0 += 1
	if mis_parity_0 == mis_parity_1:
		print(mis_parity_1)
	else:
		print(-1)


t = int(input())
for case in range(t):
	n = int(input())
	a = list(input().split())
	bad0s = 0
	bad1s = 0
	good0s = 0
	good1s = 0
	for i in range(n):
		if int(a[i]) % 2 != i % 2:
			if int(a[i]) % 2 == 0:
				bad0s = bad0s + 1
			else:
				bad1s = bad1s + 1
		elif int(a[i]) % 2 == 0:
			good0s = good0s + 1
		else:
			good1s = good1s + 1
	if bad0s + good0s == bad1s + good1s or bad0s + good0s == bad1s + good1s + 1:
		print(bad0s)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	eCount = 0
	oCount = 0
	for i in range(n):
		ind = i % 2
		ele = arr[i] % 2
		if ind == 0 and ele == 0:
			continue
		elif ind == 0 or ele == 0:
			if ele == 0:
				eCount += 1
			else:
				oCount += 1
	if eCount == oCount:
		print(eCount)
	else:
		print(-1)


def solve(n, l):
	o = 0
	e = 0
	incorrect = 0
	for i in range(n):
		if l[i] % 2 == 0:
			e += 1
		else:
			o += 1
		if l[i] % 2 == 0 and i % 2 != 0 or (l[i] % 2 != 0 and i % 2 == 0):
			incorrect += 1
	if n % 2 == 0:
		if e != o:
			return -1
	if n % 2 != 0:
		if e != o + 1:
			return -1
	return incorrect // 2
t = int(input())
for we in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(solve(n, l))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi, log
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from functools import cmp_to_key, reduce
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def solve():
	T = int(sys.stdin.readline())
	for _ in range(T):
		n = int(sys.stdin.readline())
		a = list(map(int, sys.stdin.readline().split()))
		c = 0
		(io, o, ie, e) = (0, 0, 0, 0)
		for i in range(n):
			if i & 1:
				io += 1
			else:
				ie += 1
		for i in range(n):
			if a[i] & 1:
				o += 1
			else:
				e += 1
		if ie == e and io == o:
			for i in range(n):
				if i & 1 and a[i] & 1:
					c += 1
				if not i & 1 and (not a[i] & 1):
					c += 1
			print((n - c) // 2)
		else:
			print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
solve()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	oa = 0
	ea = 0
	for i in range(n):
		if i % 2 == 0:
			if i % 2 != l[i] % 2:
				ea += 1
		if i % 2 == 1:
			if i % 2 != l[i] % 2:
				oa += 1
	if ea != oa:
		print(-1)
	else:
		print(ea)


t = int(input())
for i in range(t):
	n = int(input())
	ls = [int(a) for a in input().split()]
	(odds, evens) = (0, 0)
	for j in range(n):
		if j % 2 != ls[j] % 2:
			if j % 2 == 1:
				odds += 1
			else:
				evens += 1
	if odds == evens:
		print(odds)
	else:
		print(-1)


t = int(input())
for i in range(t):
	ecount = 0
	ocount = 0
	n = int(input())
	arr = [int(i) for i in input().split()]
	for i in range(0, n, 2):
		if arr[i] % 2 != 0:
			ecount += 1
	for i in range(1, n, 2):
		if arr[i] % 2 != 1:
			ocount += 1
	if ecount == ocount:
		print(ecount)
	else:
		print(-1)


from __future__ import division, print_function
import os, sys
import math
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(arr):
	return collections.Counter(arr)

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		cou1 = 0
		cou2 = 0
		for i in range(n):
			if a[i] % 2 != i % 2:
				if a[i] % 2 == 1:
					cou1 += 1
				else:
					cou2 += 1
		if cou1 != cou2:
			print(-1)
		else:
			print(cou1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


z = int(input())
for m in range(z):
	n = int(input())
	x = [int(i) for i in input().split()]
	y = []
	for i in range(len(x)):
		y.append(x[i] % 2)
	res = [y[i] for i in range(len(y)) if i % 2 != 0]
	res1 = [y[i] for i in range(len(y)) if i % 2 != 1]
	c_res = 0
	c_res1 = 0
	for i in res:
		if i == 0:
			c_res += 1
	for i in res1:
		if i == 1:
			c_res1 += 1
	if c_res == c_res1:
		print(c_res)
	else:
		print(-1)


t = int(input())
for tit in range(t):
	n = int(input())
	odds = 0
	evens = 0
	a = input().split()
	a = list(map(int, a))
	for (i, ele) in enumerate(a):
		if i % 2 != ele % 2:
			if i % 2 == 0:
				evens += 1
			else:
				odds += 1
	if evens == odds:
		print(evens)
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	nums = list(map(int, input().rstrip().split()))
	t1 = 0
	t2 = 0
	for (i, val) in enumerate(nums):
		if i % 2 != val % 2:
			if val & 1:
				t1 += 1
			else:
				t2 += 1
	if t1 != t2:
		print(-1)
	else:
		print(t1)


testcases = int(input())
for i in range(testcases):
	N = int(input())
	A = list(map(int, input().split()))
	cnt1 = 0
	cnt2 = 0
	for i in range(N):
		if A[i] & 1 == 1 and i & 1 == 0:
			cnt1 += 1
		elif A[i] & 1 == 0 and i & 1 == 1:
			cnt2 += 1
	if cnt1 == cnt2:
		print(cnt1)
	else:
		print(-1)


nhv = int(input())
for i in range(nhv):
	hv = int(input())
	lhv = list(map(int, input().split()))
	hv1 = []
	hv0 = []
	for j in range(hv):
		if j % 2 != lhv[j] % 2:
			if lhv[j] % 2 == 1:
				hv1.append(1)
			else:
				hv0.append(0)
	if len(hv1) == len(hv0):
		print(len(hv1))
	else:
		print(-1)


t = int(input())
for x in range(t):
	length = int(input())
	lst = list(map(int, input().split()))
	noe = 0
	neo = 0
	for i in range(length):
		if i % 2 == 0 and lst[i] % 2 != 0:
			noe += 1
		if i % 2 == 1 and lst[i] % 2 != 1:
			neo += 1
	if noe != neo:
		print(-1)
	else:
		print(noe)


def oneCount(size, array):
	n = 0
	count = 0
	while n < size:
		if array[n] == 1:
			count = count + 1
		n = n + 1
	return count

def modCompare(size, array):
	n = 0
	count = 0
	if oneCount(size, array) != size // 2:
		return -1
	while n < size - 1:
		if n % 2 == 0 and array[n] == 1:
			m = n + 1
			while m < size:
				if m % 2 == 1 and array[m] == 0:
					array[n] = 0
					array[m] = 1
					count = count + 1
				m = m + 1
		elif n % 2 == 1 and array[n] == 0:
			m = n + 1
			while m < size:
				if m % 2 == 0 and array[m] == 1:
					array[n] = 1
					array[m] = 0
					count = count + 1
				m = m + 1
		n = n + 1
	return count

def main():
	t = int(input())
	r = 0
	while r < t:
		size = int(input())
		s = input().split()
		array = [int(x) % 2 for x in s]
		print(modCompare(size, array))
		r = r + 1
	return 0
main()


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for i in range(t):
	l = inp()
	q = inlt()
	cteo = 0
	ctoe = 0
	for j in range(l):
		if j % 2 == 0:
			if q[j] % 2 == 1:
				ctoe = ctoe + 1
		elif q[j] % 2 == 0:
			cteo = cteo + 1
	if cteo == ctoe:
		print(ctoe)
	else:
		print(-1)


from math import ceil
for _ in range(int(input())):
	n = int(input())
	c = d = 0
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i] % 2 == 0:
			c += 1
		if i % 2 == 0 and l[i] % 2 != 0:
			d += 1
	if c == ceil(n / 2):
		print(d)
	else:
		print(-1)


def check(arr):
	count = 0
	for x in range(len(arr)):
		if x % 2 == 0 and arr[x] % 2 == 1 or (x % 2 == 1 and arr[x] % 2 == 0):
			count += 1
	return count // 2

def count(arr):
	odd = 0
	even = 0
	for x in arr:
		if x % 2 == 0:
			even += 1
		else:
			odd += 1
	return (odd, even)
t = int(input())
for x in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	(odd, even) = count(arr)
	if n % 2 == 0 and odd != even or (n % 2 == 1 and even - odd != 1):
		print(-1)
	else:
		print(check(arr))


def solve():
	N = int(input())
	arr = list(map(int, input().split()))
	(odd, even) = (0, 0)
	for x in arr:
		if x % 2 == 0:
			even += 1
		else:
			odd += 1
	if N % 2 == 0:
		if odd != N // 2 or even != N // 2:
			return -1
	elif even != N // 2 + 1 or odd != N // 2:
		return -1
	ans = 0
	i = 0
	while i < N:
		if arr[i] % 2 != 0:
			ans += 1
		i += 2
	return ans

def main():
	for _ in range(int(input())):
		print(solve())
main()


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	n = int(input())
	arr = list_input()
	odd_pe_even = []
	even_pe_odd = []
	for i in range(n):
		if i % 2 != arr[i] % 2:
			if i % 2 == 0:
				even_pe_odd.append(i)
			else:
				odd_pe_even.append(i)
	if len(odd_pe_even) == len(even_pe_odd) and len(odd_pe_even) == 0:
		print(0)
	elif len(odd_pe_even) == len(even_pe_odd):
		print(len(odd_pe_even))
	else:
		print(-1)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b0 = 0
	b1 = 0
	for j in range(n):
		if a[j] % 2 == 0 and j % 2 == 1:
			b0 += 1
		if a[j] % 2 == 1 and j % 2 == 0:
			b1 += 1
	if b0 == b1:
		print(b0)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))

	def indexGen(a):
		temp = list(range(a))
		return mainGen(temp)

	def mainGen(a):
		temp = []
		for i in a:
			temp.append(i % 2)
		return temp
	list1 = mainGen(a)
	list2 = indexGen(n)
	if list1 == list2:
		print(0)
	else:
		list1Sorted = list1.copy()
		list2Sorted = list2.copy()
		list2Sorted.sort()
		list1Sorted.sort()
		if list1Sorted != list2Sorted:
			print(-1)
		else:
			count = 0
			i = 0
			while i < n:
				if list1[i] != list2[i]:
					count += 1
				i += 1
			print(count // 2)


num = int(input())
for i in range(num):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	countOdd = 0
	countEven = 0
	for i in range(n):
		if i % 2 != arr[i] % 2 and arr[i] % 2 != 0:
			countOdd += 1
		elif i % 2 != arr[i] % 2 and arr[i] % 2 == 0:
			countEven += 1
	if countOdd != countEven:
		print(-1)
	else:
		print(countEven)


for _ in range(int(input())):
	e = 0
	o = 0
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	for j in range(n):
		x = list1[j]
		int(x)
		if x % 2 == 0 and j % 2 == 1:
			e += 1
		elif x % 2 == 1 and j % 2 == 0:
			o += 1
	if e == o:
		print(e)
	else:
		print('-1')


for i in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	odd = 0
	eve = 0
	correct = 0
	for j in range(n):
		if j % 2 == 0:
			if lis[j] % 2 != 0:
				eve += 1
		elif lis[j] % 2 == 0:
			odd += 1
	if odd == eve:
		print(odd)
	else:
		print(-1)


import math
for _ in range(int(input())):
	n = int(input())
	(x, y) = (0, 0)
	c = 0
	A = [int(_) for _ in input().split()]
	for _ in range(n):
		if A[_] % 2 == 0:
			x += 1
		else:
			y += 1
		if _ % 2 != A[_] % 2:
			c += 1
	if n % 2 == 0:
		if x == y:
			print(math.ceil(c / 2))
		else:
			print(-1)
	elif x == y + 1:
		print(math.ceil(c / 2))
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	oddl = 0
	evenl = 0
	for i in range(len(a)):
		if i % 2 == a[i] % 2:
			continue
		else:
			if i % 2 == 0 and a[i] % 2 != 0:
				evenl += 1
			if i % 2 != 0 and a[i] % 2 == 0:
				oddl += 1
	if oddl == evenl:
		print(evenl)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	incodd = 0
	inceven = 0
	for i in range(1, n, 2):
		if a[i] % 2 == 0:
			incodd += 1
	for i in range(0, n, 2):
		if a[i] % 2 == 1:
			inceven += 1
	if incodd != inceven:
		print(-1)
	else:
		print(incodd)


t = int(input())
for i in range(t):
	lenArr = int(input())
	arr = list(map(int, input().split()))
	par1 = 0
	par0 = 0
	for i in range(lenArr):
		if i % 2 == 0 and arr[i] % 2 == 1:
			par1 += 1
		if i % 2 == 1 and arr[i] % 2 == 0:
			par0 += 1
	if par0 == par1:
		print(par0)
	else:
		print(-1)


test = int(input())
for t in range(test):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	if len(arr) == n:
		even = []
		odd = []
		i = 0
		for i in range(n):
			if i % 2 == 0:
				even.append(arr[i])
			else:
				odd.append(arr[i])
		even_arr_odd_count = 0
		for i in even:
			if i % 2 == 1:
				even_arr_odd_count += 1
		odd_arr_even_count = 0
		for i in odd:
			if i % 2 == 0:
				odd_arr_even_count += 1
		if even_arr_odd_count == odd_arr_even_count:
			print(even_arr_odd_count)
		else:
			print('-1')


from typing import List

def solve(a: List[int]) -> int:
	counter = [0, 0]
	for (k, v) in enumerate(a):
		if k % 2 != v % 2:
			counter[v % 2] += 1
	return -1 if counter[0] != counter[1] else counter[0]
tc = int(input())
while tc > 0:
	n = int(input())
	print(solve(list(map(int, input().split()))))
	tc -= 1


def solve(n, l):
	c1 = 0
	c2 = 0
	for i in range(n):
		if i % 2 == 0 and l[i] % 2 != 0:
			c1 += 1
		elif i % 2 != 0 and l[i] % 2 == 0:
			c2 += 1
	if c1 == c2:
		print(c1)
	else:
		print(-1)
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	solve(n, l)


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		(e, o) = (0, 0)
		for i in range(n):
			if i % 2 == 0:
				if a[i] & 1:
					e += 1
			elif a[i] % 2 == 0:
				o += 1
		ans = e
		if e != o:
			ans = -1
		print(ans)
solve()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	bad_odd = 0
	bad_eve = 0
	for i in range(n):
		if i % 2 != l[i] % 2:
			if l[i] % 2 == 0:
				bad_eve += 1
			else:
				bad_odd += 1
	if bad_eve == bad_odd:
		print(bad_odd)
	else:
		print(-1)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	a_even = []
	a_odd = []
	for i in range(0, n):
		if i % 2 == 0 and a[i] % 2 == 0 or (i % 2 != 0 and a[i] % 2 != 0):
			continue
		elif a[i] % 2 == 0:
			a_even.append(a[i])
		else:
			a_odd.append(a[i])
	if len(a_even) == len(a_odd):
		print(len(a_even))
	else:
		print(-1)
	t -= 1


def main(lis):
	if len(lis) // 2 != sum(lis):
		return -1
	count = 0
	for i in range(len(lis)):
		if i % 2 != lis[i]:
			count += 1
	return count // 2
n = int(input())
for i in range(n):
	k = int(input())
	x = list(map(lambda x: int(x) % 2, input().split()))
	print(main(x))


def fun(arr, n):
	odd = 0
	even = 0
	od = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			even += 1
		else:
			odd += 1
			if i % 2 == 1:
				od += 1
	if odd != n // 2:
		return -1
	return odd - od
t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	print(fun(arr, n))
	t -= 1


import sys
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

def solve():
	(n,) = I()
	a = I()
	count = [0, 0, 0]
	for i in range(n):
		if i % 2 == a[i] % 2:
			continue
		count[a[i] % 2] += 1
	if count[0] != count[1]:
		print(-1)
	else:
		print(count[0])
(t,) = I()
while t:
	t -= 1
	solve()


tests = int(input())
for _ in range(tests):
	_ = input()
	nums = map(int, input().split(' '))
	bad = [0, 0]
	parity = 0
	for num in nums:
		if num % 2 != parity:
			bad[parity] += 1
		parity = not parity
	print(bad[0] if bad[0] == bad[1] else -1)