human
Theofanis started playing the new online game called "Among them". However, he always plays with Cypriot players, and they all have the same name: "Andreas" (the most common name in Cyprus).

In each game, Theofanis plays with n other players. Since they all have the same name, they are numbered from 1 to n.

The players write m comments in the chat. A comment has the structure of "i j c" where i and j are two distinct integers and c is a string (1 ≤ i, j ≤ n.
i ≠ j.
c is either imposter or crewmate). The comment means that player i said that player j has the role c.

An imposter always lies, and a crewmate always tells the truth. 

Help Theofanis find the maximum possible number of imposters among all the other Cypriot players, or determine that the comments contradict each other (see the notes for further explanation).

Note that each player has exactly one role: either imposter or crewmate.

Input

The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases. Description of each test case follows.

The first line of each test case contains two integers n and m (1 ≤ n ≤ 2 ⋅ 10^5.
0 ≤ m ≤ 5 ⋅ 10^5) — the number of players except Theofanis and the number of comments.

Each of the next m lines contains a comment made by the players of the structure "i j c" where i and j are two distinct integers and c is a string (1 ≤ i, j ≤ n.
i ≠ j.
c is either imposter or crewmate).

There can be multiple comments for the same pair of (i, j).

It is guaranteed that the sum of all n does not exceed 2 ⋅ 10^5 and the sum of all m does not exceed 5 ⋅ 10^5.

Output

For each test case, print one integer — the maximum possible number of imposters. If the comments contradict each other, print -1.

Example

Input

5
3 2
1 2 imposter
2 3 crewmate
5 4
1 3 crewmate
2 5 crewmate
2 4 imposter
3 4 imposter
2 2
1 2 imposter
2 1 crewmate
3 5
1 2 imposter
1 2 imposter
3 2 crewmate
3 2 crewmate
1 3 imposter
5 0

Output

2
4
-1
2
5

Note

In the first test case, imposters can be Andreas 2 and 3.

In the second test...
class Write me a Python program to find the maximum possible number of imposters among all the other Cypriot players, or determine that the comments contradict each other (see the notes for further explanation)?
assistant
#Here is Python program to find the maximum possible number of imposters among all the other Cypriot players, or determine that the comments contradict each other (see the notes for further explanation).
 UnionFind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [0]*n

    def Find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.Find(self.par[x])
            return self.par[x]

    def Unite(self, x, y):
        x = self.Find(x)
        y = self.Find(y)

        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[y] += self.par[x]
                self.par[x] = y
            else:
                self.par[x] += self.par[y]
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def Same(self, x, y):
        return self.Find(x) == self.Find(y)

    def Size(self, x):
        return -self.par[self.Find(x)]

import sys
import io, os
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

t = int(input())
for _ in range(t):
    n,m= map(int, input().split())
    C = []
    I = []
    for p in range(m):
        i, j, c = map(str, input().split())
        i, j = int(i), int(j)
        i, j = i-1, j-1
        if c == 'crewmate':
            C.append((i, j))
        else:
            I.append((i, j))
    uf = UnionFind(n)
    flag = True
    for i, j in C:
        uf.Unite(i, j)
    for i, j in I:
        if uf.Same(i, j):
            flag = False
            break
    if not flag:
        print(-1)
        continue
    P = []
    for i in range(n):
        if uf.par[i] < 0:
            P.append(i)
    toid = {}
    for i, p in enumerate(P):
        toid[p] = i
    N = len(toid)
    G = [[] for i in range(N)]
    for i, j in I:
        pi = uf.Find(i)
        pj = uf.Find(j)
        G[toid[pi]].append(toid[pj])
        G[toid[pj]].append(toid[pi])
    #print(G)
    ans = 0
    flag2 = True
    visit = [False]*N
    color = [-1]*N
    for i in range(N):
        if visit[i]:
            continue
        s = []
        V0 = set()
        V1 = set()
        s.append(i)
        visit[i] = True
        color[i] = 0
 ...