Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.

There is a garland — a cyclic rope with red and green flowers on it in some order. The sequence of flower colours is described by a string $s$; since the rope is cyclic, each two consecutive flowers are adjacent and the first and last flower are also adjacent.

The garland is *beautiful* if there is no pair of adjacent flowers with identical colours.

You want the garland to be beautiful. To achieve that, you may perform the following operation at most once:
Make two cuts on the rope (not intersecting the flowers), splitting the garland into two parts.
Reverse one of these two parts.
Tie together corresponding endpoints of the two parts, creating one whole garland again.

Can you find out whether it is possible to make the garland beautiful?

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains a single string $s$ describing the garland. Each character of $s$ is either 'R' or 'G', denoting a red or green flower respectively.

------  Output ------
For each test case, print a single line containing the string "yes" if the garland can be made beautiful or "no" otherwise.

------  Constraints ------
$1 ≤ T ≤ 10^{5}$
$2 ≤ |s| ≤ 10^{5}$
the sum of $|s|$ over all test cases does not exceed $10^{6}$

----- Sample Input 1 ------ 
3

RG

RRGG

RR
----- Sample Output 1 ------ 
yes

yes

no
----- explanation 1 ------ 
Example case 1: The garland is already beautiful.

Example case 2: We can cut the garland between flowers 1 and 2 and between flowers 3 and 4. After reversing the part containing flowers 2 and 3 and rejoining, we obtain "RGRG".

Difficulty: MEDIUM_HARD

Solutions:
for _ in range(int(input())):
	s = str(input())
	cr = s.count('R')
	l = len(s)
	cg = l - cr
	if cr == cg:
		c = 0
		if s[l - 1] == 'R' and s[l - 1] == s[0]:
			c += 1
		for i in range(l - 1):
			if s[i] == 'R' and s[i + 1] == 'R':
				c += 1
				if c > 1:
					break
		if c < 2:
			print('yes')
		else:
			print('no')
	else:
		print('no')


for _ in range(int(input())):
	s = input()
	n = len(s)
	rc = s.count('R')
	gc = n - rc
	if rc != gc:
		print('no')
		continue
	c = 0
	for i in range(n - 1):
		if s[i] == 'R' and s[i + 1] == 'R':
			c += 1
			if c > 1:
				break
	if s[0] == 'R' and s[-1] == 'R':
		c += 1
	if c > 1:
		print('no')
	else:
		print('yes')


for u in range(int(input())):
	s = input()
	r = 0
	g = 0
	count = 0
	n = len(s)
	for i in range(len(s)):
		if s[i] == 'R':
			r += 1
		else:
			g += 1
	if r == g:
		for i in range(len(s) - 1):
			if s[i] == 'R' and s[i + 1] == 'R':
				count += 1
		if s[n - 1] == 'R' and s[n - 1] == s[0]:
			count += 1
		if count == 1 or count == 0:
			print('yes')
		else:
			print('no')
	else:
		print('no')


for _ in range(int(input())):
	s = str(input())
	n = len(s)
	minIndex = -1
	maxIndex = -1
	adj = 0
	if s[0] == s[-1]:
		adj += 1
		minIndex = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			adj += 1
			if minIndex == -1:
				minIndex = i
			else:
				maxIndex = i
	if adj == 0:
		print('yes')
	elif adj != 2:
		print('no')
	elif s[minIndex] == s[maxIndex - 1]:
		print('no')
	else:
		print('yes')


for _ in range(int(input())):
	garland = input()
	size = len(garland)
	(starti, endi) = (-1, -1)
	i = 0
	while i < size - 1:
		if garland[i] == garland[i + 1]:
			starti = i + 1
			break
		i += 1
	i = size - 1
	while i > 0:
		if garland[0] == garland[-1]:
			endi = size - 1
			break
		if garland[i] == garland[i - 1]:
			endi = i - 1
			break
		i -= 1
	if starti == -1 and endi == -1:
		print('yes')
		continue
	new_garland = garland[:starti] + garland[endi:starti - 1:-1] + garland[endi + 1:]
	i = 0
	while i < size - 1:
		if new_garland[i] == new_garland[i + 1]:
			break
		i += 1
	if i == size - 1 and new_garland[-1] != new_garland[0]:
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	s = input()
	rr = s.count('RR') + s.count('RRR')
	if s[0] == s[-1] == 'R':
		rr += 1
	gg = s.count('GG') + s.count('GGG')
	if s[0] == s[-1] == 'G':
		gg += 1
	if rr == 0 and gg == 0:
		print('yes')
	elif rr == 1 and gg == 1:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	s = input()
	if len(s) % 2 != 0:
		print('no')
	else:
		rr = s.count('RR')
		gg = s.count('GG')
		rrr = s.count('RRR')
		ggg = s.count('GGG')
		if ggg or rrr:
			print('no')
		elif rr > 1 or gg > 1:
			print('no')
		elif rr == 1 and gg == 1:
			print('yes')
		elif rr == 0 and gg == 0:
			print('yes')
		elif rr == 1 and s[0] == s[-1] == 'G':
			print('yes')
		elif gg == 1 and s[0] == s[-1] == 'R':
			print('yes')
		else:
			print('no')


for _ in range(int(input())):
	T = input()
	if len(T) & 1:
		print('no')
		continue
	rcount = 0
	gcount = 0
	ecount = 0
	for i in range(len(T) - 1):
		if T[i] == 'R':
			rcount += 1
		else:
			gcount += 1
		if T[i] == T[i + 1]:
			ecount += 1
	if T[-1] == 'R':
		rcount += 1
	else:
		gcount += 1
	if rcount != gcount or ecount > 2:
		print('no')
	else:
		print('yes')


for _ in range(int(input())):
	l = list(input())
	r = 0
	g = 0
	c = 0
	if len(l) & 1:
		print('no')
		continue
	for a in range(len(l) - 1):
		if l[a] == 'R':
			r += 1
		else:
			g += 1
		if l[a] == l[a + 1]:
			c += 1
	if l[-1] == 'R':
		r += 1
	else:
		g += 1
	if r != g or c > 2:
		print('no')
	else:
		print('yes')


t = int(input())
for j in range(t):
	s = input()
	a = s.count('R')
	b = len(s) - a
	if a == b:
		c = 0
		for i in range(len(s) - 1):
			if s[i] == s[i + 1]:
				c += 1
		if s[0] == s[-1]:
			c += 1
		if c > 2:
			print('no')
		else:
			print('yes')
	else:
		print('no')


tc = int(input())
for _ in range(tc):
	s = list(input())
	r = s.count('R')
	g = s.count('G')
	if r != g:
		print('no')
	else:
		bool = True
		gorb = 0
		for i in range(len(s) - 1):
			if s[i] == s[i + 1]:
				gorb += 1
		if s[0] == s[-1]:
			gorb += 1
		if gorb > 2:
			bool = False
		print('yes' if bool else 'no')


T = int(input())
for _ in range(T):
	garland = input()
	rCount = garland.count('R')
	gCount = garland.count('G')
	if 'RRR' in garland or 'GGG' in garland:
		print('no')
	elif garland.count('RR') > 1 or garland.count('GG') > 1:
		print('no')
	elif garland.count('R') == garland.count('G'):
		print('yes')
	else:
		print('no')


def work(s):
	(rc, gc) = (0, 0)
	n = len(s) - 1
	s.count('R')
	if s[0] == s[n]:
		if s[0] == 'R':
			rc += 1
		else:
			gc += 1
	rr = 1 if s[0] == 'R' else 0
	for i in range(n):
		if s[i + 1] == 'R':
			rr += 1
		if s[i] == s[i + 1]:
			if s[i] == 'R':
				rc += 1
			else:
				gc += 1
	if rc < 2 and gc < 2 and (n + 1 == 2 * rr):
		return 'yes'
	return 'no'
t = int(input())
for _ in range(t):
	s = input()
	print(work(s))


for _ in range(int(input())):
	s = input()
	c1 = c2 = c3 = c4 = 0
	for i in s:
		if i == 'G':
			c3 += 1
		else:
			c4 += 1
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			if s[i] == 'G':
				c1 += 1
			else:
				c2 += 1
	if s[-1] == s[0] and len(s) > 2:
		if s[-1] == 'G':
			c1 += 1
		else:
			c2 += 1
	if c3 == 0 and c4 > 1 or (c4 == 0 and c3 > 1):
		print(f'no')
	elif c1 > 1 or c2 > 1:
		print(f'no')
	elif c1 != c2:
		print(f'no')
	else:
		print(f'yes')


import sys
import copy
import math
import heapq
import bisect
import random
import operator
import statistics
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from heapq import heapify, heappush, heappop
from itertools import permutations, combinations
from collections import Counter, OrderedDict, deque
from bisect import bisect_left as bl, bisect_right as br
from functools import lru_cache, reduce, total_ordering, update_wrapper, partial
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strr = lambda : input().strip()
jl = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
muli = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod1 = 1000000007
mod2 = 998244353
for i in range(int(input())):
	l = input()
	(r, g) = (0, 0)
	for i in range(len(l)):
		if l[i] == 'G' and l[i - 1] == 'G':
			g += 1
		elif l[i] == 'R' and l[i - 1] == 'R':
			r += 1
	if l.count('R') == l.count('G') and r <= 1 and (g <= 1):
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	s = input()
	flag = 0
	if len(s) % 2 == 0:
		countr = 0
		countg = 0
		for i in range(0, len(s) - 1):
			if s[i] == 'R' and s[i + 1] == 'R':
				countr += 1
			if s[i] == 'G' and s[i + 1] == 'G':
				countg += 1
		if s[0] == s[-1]:
			if s[0] == 'R':
				countr += 1
			else:
				countg += 1
		if countr == 0 and countg == 0 or (countr == 1 and countg == 1):
			flag = 1
	if flag:
		print('yes')
	else:
		print('no')


t = int(input())
while t:
	t = t - 1
	s = input()
	a = s.count('R')
	b = s.count('G')
	if s.count('RR') > 1 or s.count('GG') > 1 or 'RRR' in s or ('GGG' in s):
		print('no')
	elif len(s) % 2 == 0 and a == b:
		print('yes')
	else:
		print('no')


t = int(input())
from collections import Counter
for _ in range(t):
	s = input()
	if 'RRR' in s or 'GGG' in s:
		print('no')
	elif s.count('RR') > 1 or s.count('GG') > 1:
		print('no')
	else:
		r = s.count('R')
		g = s.count('G')
		if len(s) == 2:
			if r == 1:
				print('yes')
			else:
				print('no')
		elif len(s) % 2 == 0 and r == g:
			print('yes')
		else:
			print('no')


for _ in range(int(input())):
	s = input()
	x = len(s)
	count = 0
	r_count = 0
	g_count = 0
	for i in s:
		if i == 'R':
			r_count += 1
		else:
			g_count += 1
	if x % 2 != 0:
		print('no')
	else:
		for i in range(x):
			if i < x - 1:
				if s[i] == s[i + 1]:
					count += 1
		if s[0] == s[x - 1]:
			count += 1
		if r_count == g_count and count <= 2:
			print('yes')
		else:
			print('no')


t = int(input())
for i in range(t):
	m = 0
	n = 0
	x = str(input())
	a = len(x)
	for j in range(a):
		if 'R' == x[j] and x[j - 1] == 'R':
			m += 1
		elif 'G' == x[j] and x[j - 1] == 'G':
			n += 1
	if x.count('R') == x.count('G') and m <= 1 and (n <= 1):
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	l = input()
	r = 0
	g = 0
	for i in range(len(l)):
		if l[i] == 'G' and l[i - 1] == 'G':
			g += 1
		elif l[i] == 'R' and l[i - 1] == 'R':
			r += 1
	if l.count('R') == l.count('G') and r <= 1 and (g <= 1):
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	l = input()
	ls = [i for i in l]
	s = 0
	r = 0
	g = 0
	rr = 0
	gg = 0
	if len(ls) % 2 == 1:
		print('no')
	else:
		for i in range(len(ls) - 1):
			if ls[i] == 'R':
				rr += 1
			if ls[i] == 'G':
				gg += 1
			if ls[i] == ls[i + 1]:
				s += 1
				if ls[i] == 'R':
					r += 1
				if ls[i] == 'G':
					g += 1
		if ls[-1] == 'R':
			rr += 1
		if ls[-1] == 'G':
			gg += 1
		if s > 2:
			print('no')
		elif s <= 2:
			if rr == gg:
				print('yes')
			else:
				print('no')
		else:
			print('no')


t = int(input())

def countPairs(s):
	rpair = gpair = 0
	for i in range(1, len(s)):
		if s[i - 1] == s[i]:
			if s[i - 1] == 'R':
				rpair += 1
			elif s[i - 1] == 'G':
				gpair += 1
	return (rpair, gpair)

def checkF(s, rcount, gcount):
	if rcount == gcount:
		(rpair, gpair) = countPairs(s)
		if rpair > 1 or gpair > 1:
			return -1
	else:
		return -1
for t in range(t):
	s = input()
	rcount = s.count('R')
	gcount = s.count('G')
	ans = checkF(s, rcount, gcount)
	if ans == -1:
		print('no')
	else:
		print('yes')


t = int(input())
for _ in range(t):
	s = input()
	(r, g) = (0, 0)
	for i in range(len(s)):
		if s[i] == s[i - 1]:
			if s[i] == 'R':
				r += 1
			else:
				g += 1
	print('yes' if r == g and r in [0, 1] else 'no')


t = int(input())
while t:
	t -= 1
	sequence = input()
	count_r = 0
	count_g = 0
	for i in sequence:
		if i == 'R':
			count_r += 1
		else:
			count_g += 1
	if count_g != count_r:
		print('no')
	else:
		count_pair_r = 0
		count_pair_g = 0
		for i in range(1, len(sequence)):
			if sequence[i - 1] == 'G' and sequence[i] == 'G':
				count_pair_g += 1
			if sequence[i - 1] == 'R' and sequence[i] == 'R':
				count_pair_r += 1
		if count_pair_r > 1 or count_pair_g > 1:
			print('no')
		else:
			print('yes')


t = int(input())
for i in range(t):
	l = list(map(str, input().strip()))
	count = 0
	if len(l) % 2 == 1:
		print('no')
	elif len(l) // 2 != l.count('R'):
		print('no')
	else:
		for i in range(len(l) - 1):
			if l[i] == l[i + 1]:
				count += 1
		if l[0] == l[-1]:
			count += 1
		if count < 3:
			print('yes')
		else:
			print('no')


for _ in range(int(input())):
	garland = input()
	pair_r = 0
	pair_g = 0
	for i in range(len(garland)):
		if garland[i] == 'G' and garland[i - 1] == 'G':
			pair_g += 1
		elif garland[i] == 'R' and garland[i - 1] == 'R':
			pair_r += 1
	if garland.count('R') == garland.count('G') and pair_g <= 1 and (pair_r <= 1):
		print('yes')
	else:
		print('no')


def can_be_done(s):
	if len(s) % 2 == 1:
		return False
	if s.count('R') != s.count('G'):
		return False
	if is_cyclic_rope(s):
		return True
	correctRope = 'RG' * (len(s) // 2)
	wrongNotches = [i for i in range(0, len(s)) if s[i] != correctRope[i]]
	(L, R) = (wrongNotches[0], wrongNotches[-1])
	s_new = s[:L] + s[L:R + 1][::-1] + s[R + 1:]
	if is_cyclic_rope(s_new):
		return True
	correctRope = 'GR' * (len(s) // 2)
	wrongNotches = [i for i in range(0, len(s)) if s[i] != correctRope[i]]
	(L, R) = (wrongNotches[0], wrongNotches[-1])
	s_new = s[:L] + s[L:R + 1][::-1] + s[R + 1:]
	if is_cyclic_rope(s_new):
		return True
	return False

def is_cyclic_rope(s):
	return all((s[i] != s[i + 1] for i in range(len(s) - 1)))
for _ in range(int(input())):
	s = input()
	print(['no', 'yes'][can_be_done(s)])


z = int(input())
while z:
	z -= 1
	a = list(str(input()))
	b = len(a)
	a.append(a[0])
	(cr, cg) = (0, 0)
	for i in range(0, b - 1):
		if a[i] == a[i + 1]:
			if a[i] == 'R':
				cr += 1
			if a[i] == 'G':
				cg += 1
	a.pop(-1)
	if cr > 1 or cg > 1 or a.count('R') != a.count('G'):
		print('no')
	else:
		print('yes')


T = int(input())
for t in range(T):
	garland = input()
	(con_r, con_g) = (0, 0)
	for i in range(len(garland) - 1):
		if garland[i] == garland[i + 1]:
			if garland[i] == 'R':
				con_r += 1
			else:
				con_g += 1
	if garland[0] == garland[-1]:
		if garland[0] == 'R':
			con_r += 1
		else:
			con_g += 1
	if not garland.count('G') == garland.count('R') or con_g > 1 or con_r > 1:
		print('no')
	else:
		print('yes')


def change(s):
	if s == '1':
		return '0'
	else:
		return '1'
case = int(input())
for _ in range(case):
	s = input()
	n = len(s)
	R = 0
	G = 0
	ns = ''
	for i in range(n):
		if s[i] == 'R':
			ns += '1'
			R += 1
		if s[i] == 'G':
			ns += '0'
			G += 1
	if R != G:
		print('no')
	else:
		step = 0
		ch = False
		f = change(ns[0])
		ans = 'yes'
		for i in range(1, n):
			if f == ns[i]:
				if ch:
					ch = False
				f = change(ns[i])
			else:
				if not ch:
					ch = True
					step += 1
					if step > 1:
						ans = 'no'
						break
				f = ns[i]
		print(ans)


for _ in range(int(input())):
	s = input()
	g = 0
	r = 0
	for x in range(len(s) - 1):
		if s[x] == s[x + 1]:
			if s[x] == 'G':
				g += 1
			if s[x] == 'R':
				r += 1
	if g > 1 or r > 1 or s.count('G') != s.count('R'):
		print('no')
	else:
		print('yes')


n = int(input())
for i in range(n):
	s = str(input())
	if s == 'RG':
		print('yes')
	elif s == 'GR':
		print('yes')
	elif s == 'RR':
		print('no')
	elif s == 'GG':
		print('no')
	else:
		s = s + s[0]
		i = 0
		index = []
		while i < len(s) - 1:
			if s[i] == s[i + 1]:
				index.append(i)
			i += 1
		if len(index) > 2:
			print('no')
		elif len(index) == 2:
			if s[index[0]] != s[index[1]]:
				print('yes')
			else:
				print('no')
		elif len(index) == 1:
			print('no')
		elif len(index) == 0:
			print('yes')


n = int(input())
for i in range(n):
	s = str(input())
	s = s + s[0]
	x = 0
	y = 0
	j = 0
	while j < len(s) - 1:
		if s[j] == 'R' and s[j + 1] == 'R':
			x += 1
		elif s[j] == 'G' and s[j + 1] == 'G':
			y += 1
		j += 1
	if x == 0 and y == 0 or (x == 1 and y == 1):
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	s = str(input())
	x = 0
	y = 0
	s += s[0]
	for i in range(len(s) - 1):
		if s[i] == 'R' and s[i + 1] == 'R':
			x += 1
		if s[i] == 'G' and s[i + 1] == 'G':
			y += 1
	if x == 0 and y == 0 or (x == 1 and y == 1):
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	a = input()
	l = [0, 0]
	for i in range(len(a)):
		if a[i] == a[(i + 1) % len(a)] and a[i] == 'R':
			l[0] += 1
		elif a[i] == a[(i + 1) % len(a)] and a[i] == 'G':
			l[1] += 1
	if l[0] == l[1] and l[1] < 2:
		print('yes')
	else:
		print('no')


import sys
from math import gcd, sqrt, ceil, log

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

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

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

def ip():
	return input()
for tastcas in range(int(input())):
	s = ip()
	n = len(s)
	s += s[0]
	invG = 0
	invR = 0
	for i in range(n):
		if s[i] == 'R' and s[i + 1] == 'R':
			invR += 1
		if s[i] == 'G' and s[i + 1] == 'G':
			invG += 1
	if invR == 0 and invG == 0 or (invR == 1 and invG == 1):
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	s = input()
	r = 0
	b = 0
	for i in range(len(s)):
		if s[i] == s[(i + 1) % len(s)]:
			if s[i] == 'R':
				r = r + 1
			else:
				b = b + 1
	if r == 0 and b == 0:
		print('yes')
	elif r == 0 and b == 1:
		print('no')
	elif r == 1 and b == 0:
		print('no')
	elif r == 1 and b == 1:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	s = input()
	r = s.count('R')
	g = s.count('G')
	c = 0
	for i in range(len(s)):
		if i < len(s) - 1 and s[i] == s[i + 1]:
			c += 1
		if i == len(s) - 1 and s[0] == s[i]:
			c += 1
	if len(s) % 2 == 0:
		if r == g and c <= 2:
			print('yes')
		else:
			print('no')
	else:
		print('no')


t = int(input())
for i in range(t):
	s = input()
	l = len(s)
	x = 0
	y = 0
	z = 0
	for j in range(l):
		if s[j] == 'R':
			x += 1
		if s[j] == 'G':
			y += 1
		if j < l - 1 and s[j] == s[j + 1]:
			z += 1
		if j == l - 1 and s[0] == s[j]:
			z += 1
	if l % 2 == 0:
		if x == y and z <= 2:
			print('yes')
		else:
			print('no')
	else:
		print('no')


t = int(input())
for _ in range(t):
	s = input()
	(r, g) = (0, 0)
	l = len(s)
	for i in range(l - 1):
		x = (s[i], s[i + 1])
		if x == ('R', 'R'):
			r += 1
		elif x == ('G', 'G'):
			g += 1
	if l > 2:
		if (s[0], s[-1]) == ('R', 'R'):
			r += 1
		elif (s[0], s[-1]) == ('G', 'G'):
			g += 1
	if r <= 1 and g <= 1 and (r == g):
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	s = input()
	l = [s[0]] if s[0] == s[len(s) - 1] else []
	t = 'yes'
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			if s[i] in l:
				t = 'no'
				break
			l.append(s[i])
	if len(l) == 1:
		t = 'no'
	print(t)


t = int(input())
l = []
for amogh in range(t):
	s = input()
	cut = []
	rc = 0
	gc = 0
	for k in s:
		if k == 'R':
			rc += 1
		else:
			gc += 1
	if rc != gc:
		l.append('no')
	else:
		for i in range(len(s)):
			if s[i] == s[i - 1]:
				cut.append(i)
		if len(cut) in [0, 2]:
			if len(s) == len(cut):
				l.append('no')
			else:
				l.append('yes')
		else:
			l.append('no')
for j in l:
	print(j)


t = int(input())
while t:
	t -= 1
	cnt = [0, 0]
	line = [0 if x == 'R' else 1 for x in input()]
	for i in range(len(line)):
		if line[i] == line[(i + 1) % len(line)]:
			cnt[line[i]] += 1
	if cnt[0] == cnt[1] and cnt[1] < 2:
		print('yes')
	else:
		print('no')


def Solution(p, l):
	y = 'yes'
	n = 'no'
	if l % 2 != 0:
		return n
	temp = []
	for i in range(l - 1):
		if p[i] == p[i + 1]:
			temp.append(i + 1)
	if len(temp) > 2:
		return n
	if len(temp) == 2:
		if p[temp[0]] == p[temp[1]] or p[temp[0] - 1] == p[temp[1] - 1]:
			return n
		elif p[0] == p[l - 1]:
			return n
		else:
			return y
	if len(temp) == 1:
		if p[0] == p[temp[0]] or p[temp[0] - 1] == p[l - 1]:
			return n
		else:
			return y
	else:
		return y
test = int(input())
for t in range(test):
	p = input()
	n = len(p)
	print(Solution(p, n))


for _ in range(int(input())):
	check = 0
	cr = 0
	cg = 0
	s = list(input())
	s.append(s[0])
	if len(s) % 2 == 0:
		print('no')
		continue
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			check += 1
		if s[i] == 'R':
			cr += 1
		else:
			cg += 1
	if cr == cg:
		if check == 0:
			print('yes')
		elif check == 2:
			if len(s) > 3:
				print('yes')
			else:
				print('no')
		else:
			print('no')
	else:
		print('no')


T = int(input())
for _ in range(T):
	garland = list(input())
	garland_length = len(garland)
	no_of_rs = 0
	no_of_gs = 0
	limit = 2
	count = 0
	for idx in range(garland_length):
		if garland[idx] == 'R':
			no_of_rs += 1
		else:
			no_of_gs += 1
		if garland[idx] == garland[idx - 1]:
			count += 1
	if count > limit:
		limit_crossed = True
	else:
		limit_crossed = False
	if garland_length % 2 == 0:
		if no_of_rs == no_of_gs == garland_length // 2:
			if limit_crossed:
				print('no')
			else:
				print('yes')
		else:
			print('no')
	else:
		print('no')


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	poss = []
	for i in range(1, n):
		if s[i] == s[i - 1]:
			poss.append([i - 1, i])
	if s[0] == s[-1]:
		poss.append([n - 1, 0])
	if len(poss) == 0:
		print('yes')
	elif len(poss) == 1 or n == 2:
		poss = poss[0]
		if poss[0] == n - 1:
			found = False
			for i in range(1, n - 1):
				(x, y, a, b) = (0, i - 1, i, n - 1)
				if s[x] != s[a] and s[y] != s[b]:
					found = True
					break
			if found:
				print('yes')
			else:
				print('no')
		else:
			(x, y) = (0, poss[0])
			(a, b) = (poss[1], n - 1)
			if s[x] != s[a] and s[y] != s[b]:
				print('yes')
			else:
				print('no')
	elif len(poss) > 2:
		print('no')
	else:
		poss = [poss[0][0], poss[0][1], poss[1][0], poss[1][1]]
		poss.sort()
		(x, y, a, b) = poss
		if s[x] != s[a] and s[y] != s[b]:
			print('yes')
		else:
			print('no')


def solve():
	n = len(s)
	if n % 2 == 1:
		return 'no'
	cr = 0
	cg = 0
	if 'GGG' in s or 'RRR' in s:
		return 'no'
	if n >= 4:
		f = s[-2] + s[-1] + s[0] + s[1]
		if 'GGG' in s or 'RRR' in s:
			return 'no'
	if s[0] == 'R':
		cr = 1
	else:
		cg = 1
	prs = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			prs += 1
			if prs > 2:
				return 'no'
		if s[i] == 'R':
			cr += 1
		else:
			cg += 1
	if s[0] == s[-1]:
		prs += 1
		if prs > 2:
			return 'no'
	if cr != cg:
		return 'no'
	return 'yes'
t = int(input())
for _ in range(t):
	s = input()
	print(solve())


t = int(input())
while t:
	s = input()
	mp = {}
	cut = 0
	for i in range(len(s) - 1):
		mp[s[i]] = mp.get(s[i], 0) + 1
		if s[i] == s[i + 1]:
			cut += 1
	mp[s[-1]] = mp.get(s[-1], 0) + 1
	if s[-1] == s[0]:
		cut += 1
	if 'G' not in list(mp.keys()):
		mp['G'] = 0
	if 'R' not in list(mp.keys()):
		mp['R'] = 0
	if mp['R'] == mp['G'] and (cut == 2 or cut == 0):
		print('yes')
	else:
		print('no')
	t -= 1


t = int(input())
for i in range(t):
	string = input()
	consReds = 0
	consGreens = 0
	n = len(string)
	if n % 2 != 0:
		print('no')
		continue
	if string[0] == string[n - 1]:
		if string[0] == 'R':
			consReds += 1
		else:
			consGreens += 1
	for j in range(0, n - 1):
		if string[j] == string[j + 1]:
			if string[j] == 'G':
				consGreens += 1
			else:
				consReds += 1
	if consReds == 1 and consGreens == 1 or (consReds == 0 and consGreens == 0):
		print('yes')
	else:
		print('no')


def solve(s):
	r = s.count('R')
	g = s.count('G')
	n = len(s)
	if n % 2 == 0:
		if r == g:
			count = 0
			for i in range(n):
				if s[i] == s[(i + 1) % n]:
					count += 1
			if count == 0 or count == 2:
				print('yes')
			else:
				print('no')
		else:
			print('no')
	else:
		print('no')
t = int(input())
for _ in range(t):
	s = input()
	solve(s)


for i in range(int(input())):
	g = input()
	if g.count('R') == g.count('G'):
		count = 0
		for j in range(len(g)):
			if g[j] == g[(j + 1) % len(g)]:
				count += 1
		if count == 0 or count == 2:
			print('yes')
		else:
			print('no')
	else:
		print('no')


t = int(input())
while t > 0:
	t -= 1
	s = input()
	n = len(s)
	rr = 0
	gg = 0
	for i in range(n):
		j = i + 1
		if j > n - 1:
			j = 0
		if s[i] == s[j]:
			if s[i] == 'R':
				rr += 1
			else:
				gg += 1
	if rr == 0 and gg == 0:
		print('yes')
		continue
	if rr == 1 and gg == 1:
		print('yes')
	else:
		print('no')


t = int(input())
while t != 0:
	istr = input()
	rcount = 0
	gcount = 0
	istr += istr[0]
	for i in range(len(istr) - 1):
		if istr[i] == istr[i + 1]:
			if istr[i] == 'R':
				rcount += 1
			else:
				gcount += 1
	if rcount == gcount == 0 or rcount == gcount == 1:
		print('yes')
	else:
		print('no')
	t -= 1


for _ in range(int(input())):
	s = input()
	n = len(s)
	s += s[0]
	c = {'R': 0, 'G': 0}
	wr = 0
	for i in range(n):
		if s[i] == s[i + 1]:
			wr += 1
		c[s[i]] += 1
	if c['R'] != c['G']:
		print('no')
	elif wr == 0:
		print('yes')
	elif wr == 2:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	s = input()
	(cR, cG) = (0, 0)
	s += s[0]
	for i in range(len(s) - 1):
		if s[i] == s[i + 1] and s[i] == 'R':
			cR = cR + 1
		elif s[i] == s[i + 1] and s[i] == 'G':
			cG = cG + 1
	if cG == cR == 0 or cG == cR == 1:
		print('yes')
	else:
		print('no')


t = int(input())
for _ in range(t):
	S = input()
	three_in_a_row = False
	multiple_twos = False
	two_red = False
	two_green = False
	n = len(S)
	count = 1
	for i in range(n):
		if S[(i + 1) % n] == S[i]:
			count += 1
			if count == 3:
				three_in_a_row = True
				break
			if count == 2:
				if S[i] == 'R':
					if two_red:
						multiple_twos = True
						break
					two_red = True
				else:
					if two_green:
						multiple_twos = True
						break
					two_green = True
		else:
			count = 1
	if three_in_a_row or multiple_twos:
		print('no')
	elif two_red ^ two_green:
		print('no')
	else:
		print('yes')


for t in range(int(input())):
	s = input()
	if len(s) % 2 == 1:
		print('no')
		continue
	rr = s.count('R')
	gg = s.count('G')
	if rr != gg:
		print('no')
		continue
	crr = 0
	cgg = 0
	if s[0] == s[-1]:
		if s[0] == 'R':
			crr += 1
		else:
			cgg += 1
	for i in range(1, len(s)):
		if s[i] == 'R' and s[i - 1] == 'R':
			crr += 1
			if crr == 2:
				break
		elif s[i] == 'G' and s[i - 1] == 'G':
			cgg += 1
			if cgg == 2:
				break
	if cgg == crr and cgg <= 1:
		print('yes')
	else:
		print('no')


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	r = 0
	for i in s:
		if i == 'R':
			r += 1
	g = n - r
	if n % 2 == 0:
		if r == g:
			b = s[n - 1]
			rd = 0
			gr = 0
			for i in range(n):
				if s[i] == 'R' and b == 'R':
					rd += 1
				if s[i] == 'G' and b == 'G':
					gr += 1
				b = s[i]
			if rd > 1 or gr > 1:
				print('no')
			else:
				print('yes')
		else:
			print('no')
	else:
		print('no')


cases = int(input())
for i in range(cases):
	garland = input()
	g = 0
	r = 0
	for x in range(len(garland) - 1):
		if garland[x] == garland[x + 1]:
			if garland[x] == 'G':
				g += 1
			elif garland[x] == 'R':
				r += 1
	if g > 1 or r > 1 or garland.count('G') != garland.count('R'):
		print('no')
	else:
		print('yes')


a = int(input())
while a != 0:
	a = a - 1
	b = input()
	c = len(b)
	if c % 2 != 0:
		print('no')
	else:
		rg = 0
		gr = 0
		for i in range(0, c - 1):
			if b[i] == b[i + 1]:
				if b[i] == 'R':
					rg = rg + 1
				elif b[i] == 'G':
					gr = gr + 1
		if b[0] == b[c - 1]:
			if b[0] == 'R':
				rg = rg + 1
			else:
				gr = gr + 1
		if rg == 0 and gr == 0 or (rg == 1 and gr == 1):
			print('yes')
		else:
			print('no')


for _ in range(int(input())):
	b = input()
	dc = 0
	(r, g) = (0, 0)
	for i in b:
		if i == 'R':
			r += 1
		else:
			g += 1
	if len(b) % 2 or r != g:
		print('no')
	else:
		c = b[-1]
		for i in b:
			if i == c:
				dc += 1.0
			c = i
		if dc == 2 or dc == 0:
			print('yes')
		else:
			print('no')


t = int(input())
for _ in range(t):
	s = input()
	rc = 0
	gc = 0
	for i in range(len(s) - 1):
		if s[i] == s[i + 1] and s[i] == 'R':
			rc += 1
		elif s[i] == s[i + 1] and s[i] == 'G':
			gc += 1
	if s[0] == s[-1] and s[0] == 'R':
		rc += 1
	if s[0] == s[-1] and s[0] == 'G':
		gc += 1
	if rc == 1 and gc == 1 or (rc == 0 and gc == 0):
		print('yes')
	else:
		print('no')


n = int(input())
for x in range(n):
	garland = input()
	if len(garland) < 2:
		print('yes')
		continue
	options = ['R', 'G']
	value_counts_dict = {i: 0 for i in options}
	for (char1, char2) in zip(garland, garland[1:] + garland[0]):
		if char1 == char2:
			value_counts_dict[char1] += 1
	if value_counts_dict['R'] == value_counts_dict['G'] == 0 or value_counts_dict['R'] == value_counts_dict['G'] == 1:
		print('yes')
	else:
		print('no')


t = int(input())
while t > 0:
	s = str(input())
	t = t - 1
	rr = 0
	gg = 0
	cr = 0
	cg = 0
	for i in range(0, len(s) - 1):
		if s[i] == s[i + 1]:
			if s[i] + s[i + 1] == 'RR':
				rr = rr + 1
			else:
				gg = gg + 1
		if s[i] == 'R':
			cr = cr + 1
		else:
			cg = cg + 1
	if s[0] == s[-1]:
		if s[0] == 'R':
			rr = rr + 1
		else:
			gg = gg + 1
	if s[-1] == 'R':
		cr = cr + 1
	else:
		cg = cg + 1
	if cr == cg and (rr == gg and gg < 2):
		print('yes')
	else:
		print('no')


def repcount(st, su):
	count = 0
	for i in range(len(st) - 1):
		if st[i] + st[i + 1] == su:
			count += 1
	return count
t = int(input())
for _ in range(t):
	s = str(input())
	rr = repcount(s, 'RR')
	gg = repcount(s, 'GG')
	if s[0] == s[-1] == 'R':
		rr += 1
	elif s[0] == s[-1] == 'G':
		gg += 1
	if (rr == gg == 1 or rr == gg == 0) and s.count('R') == s.count('G'):
		print('yes')
	else:
		print('no')