Given a singly linked list of size N containing only English Alphabets. Your task is to complete the function arrangeC&V(), that arranges the consonants and vowel nodes of the list it in such a way that all the vowels nodes come before the consonants while maintaining the order of their arrival.
Input:
The function takes a single argument as input, the reference pointer to the head of the linked list. There will be T test cases and for each test case the function will be called separately.
Output:
For each test case output a single line containing space separated elements of the list.
User Task:
The task is to complete the function arrange() which should arrange the vowels and consonants as required.
Constraints:
1 <= T <= 100
1 <= N <= 100
Example:
Input:
2
6
a e g h i m
3
q r t
Output:
a e i g h m
q r t
Explanation:
Testcase 1: Vowels like a, e and i are in the front, and consonants like g, h and m are at the end of the list.

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3



"""

# Node Class



class node:

    def __init__(self, val):

        self.data = val

        self.next = None



"""



class Solution:

    #Function to reverse a linked list.

    def arrangeCV(self, head):

        # Code here

Solutions:
class Solution:

	def arrangeCV(self, head):
		(a, final) = ([], [])
		while head:
			a.append(head.data)
			head = head.next
		for i in a:
			if i in 'aeiou':
				final.append(i)
		for i in a:
			if i not in 'aeiou':
				final.append(i)
		for i in final:
			print(i, end=' ')


class Solution:

	def arrangeCV(self, head):
		v = []
		c = []
		temp = head
		while temp != None:
			c.append(temp.data)
			temp = temp.next
		for i in c:
			if i in 'aeiou':
				v.append(i)
		for i in c:
			if i not in 'aeiou':
				v.append(i)
		for i in v:
			print(i, end=' ')


class Solution:

	def arrangeCV(self, head):
		vowel = ['a', 'e', 'i', 'o', 'u']
		num = []
		num1 = []
		t = head
		while t:
			if t.data in vowel:
				num.append(t.data)
			else:
				num1.append(t.data)
			t = t.next
		num2 = num + num1
		r = Linked_List()
		for i in num2:
			r.insert(i)
		return r.head


class Solution:

	def arrangeCV(self, head):
		v = []
		c = []
		while head:
			if head.data in ['a', 'e', 'i', 'o', 'u']:
				v.append(head.data)
			else:
				c.append(head.data)
			head = head.next
		for i in v:
			print(i, end=' ')
		for i in c:
			print(i, end=' ')


class Solution:

	def arrangeCV(self, head):
		a = []
		b = []
		c = []
		while head != None:
			a.append(head.data)
			head = head.next
		for i in a:
			if i == 'a' or i == 'e' or i == 'i' or (i == 'u') or (i == 'o'):
				b.append(i)
			else:
				c.append(i)
		x = b + c
		for i in x:
			print(i, end=' ')


class node:

	def __init__(self, val):
		self.data = val
		self.next = None

class Solution:

	def arrangeCV(self, head):
		s = 'aeiou'
		temp = head
		vowel = []
		cons = []
		while temp:
			if temp.data in s:
				vowel.append(temp.data)
			else:
				cons.append(temp.data)
			temp = temp.next
		res1 = Node(0)
		res2 = res1
		for num in vowel:
			res1.next = Node(num)
			res1 = res1.next
		for num in cons:
			res1.next = Node(num)
			res1 = res1.next
		return res2.next


class Solution:

	def arrangeCV(self, head):
		s = 'aeiou'
		list1 = []
		a = head
		while a is not None:
			list1.append(a.data)
			a = a.next
		head1 = None
		c = None
		head2 = None
		d = None
		for i in list1:
			m = Node(i)
			if i in s:
				if head1 is None:
					head1 = m
					c = head1
				else:
					c.next = m
					c = c.next
			elif head2 is None:
				head2 = m
				d = head2
			else:
				d.next = m
				d = d.next
		if head1 is None:
			return head2
		elif head2 is None:
			return head1
		else:
			c.next = head2
			return head1


class Solution:

	def arrangeCV(self, head):
		v = []
		c = []
		z = 'aeiou'
		temp = head
		while temp:
			if temp.data in z:
				v.append(temp.data)
				temp = temp.next
			else:
				c.append(temp.data)
				temp = temp.next
		v.extend(c)
		e = len(v)
		q = 0
		a = Linked_List()
		while e:
			a.insert(v[q])
			q += 1


class node:

	def __init__(self, val):
		self.data = val
		self.next = None

class Solution:

	def arrangeCV(self, head):
		h = head
		tmp = None
		tmpp = None
		tmp2 = None
		tmpp2 = None
		while head:
			if head.data in ['a', 'e', 'i', 'o', 'u']:
				if not tmp:
					tmp = head
					tmpp = head
				else:
					tmp.next = head
					tmp = tmp.next
			elif not tmp2:
				tmp2 = head
				tmpp2 = head
			else:
				tmp2.next = head
				tmp2 = tmp2.next
			head = head.next
		if tmp2:
			tmp2.next = None
		if tmp:
			tmp.next = tmpp2
		else:
			tmpp = tmpp2
		return tmpp


class Solution:

	def arrangeCV(self, head):
		vowel = []
		consonent = []
		ptr = head
		while ptr:
			if ptr.data == 'a' or ptr.data == 'e' or ptr.data == 'i' or (ptr.data == 'o') or (ptr.data == 'u'):
				vowel.append(ptr.data)
			else:
				consonent.append(ptr.data)
			ptr = ptr.next
		ll = Linked_List()
		for i in vowel:
			ll.insert(i)
		for i in consonent:
			ll.insert(i)
		return ll.head


class Solution:

	def arrangeCV(self, head):
		l = ['a', 'e', 'i', 'o', 'u']
		l1 = []
		l2 = []
		while head:
			if head.data in l:
				l1.append(head.data)
			else:
				l2.append(head.data)
			head = head.next
		l1.extend(l2)
		new_node = Node(-1)
		a = new_node
		n = len(l1)
		i = 0
		while n:
			a.next = Node(l1[i])
			i += 1
			n -= 1
			a = a.next
		return new_node.next


class Solution:

	def arrangeCV(self, head):
		vow = []
		con = []
		t = head
		while t:
			if t.data == 'a' or t.data == 'e' or t.data == 'i' or (t.data == 'o') or (t.data == 'u'):
				vow.append(t.data)
			else:
				con.append(t.data)
			t = t.next
		tar = vow + con
		if len(vow) == 0 or len(con) == 0:
			return head
		else:
			xnx = head
			c = 0
			while xnx:
				xnx.data = tar[c]
				c += 1
				xnx = xnx.next
			return head


class Solution:

	def arrangeCV(self, head):
		c = []
		v = []
		while head is not None:
			if head.data == 'a' or head.data == 'e' or head.data == 'i' or (head.data == 'o') or (head.data == 'u'):
				v.append(head.data)
			else:
				c.append(head.data)
			head = head.next
		z = v + c
		z.append('1')
		head = None
		tail = None
		for ele in z:
			if ele != '1':
				if head is None:
					newnode = Node(ele)
					head = newnode
					tail = newnode
				else:
					newnode = Node(ele)
					tail.next = newnode
					tail = newnode
		return head


class Solution:

	def arrangeCV(self, head):
		c = []
		v = []
		while head is not None:
			if head.data == 'a' or head.data == 'e' or head.data == 'i' or (head.data == 'o') or (head.data == 'u'):
				v.append(head.data)
			else:
				c.append(head.data)
			head = head.next
		v = v + c
		head = Node(v[0])
		t = head
		for i in range(1, len(v)):
			r = Node(v[i])
			head.next = r
			head = head.next
		return t


class Solution:

	def arrangeCV(self, head):
		t = head
		v1 = ['a', 'e', 'i', 'o', 'u']
		l1 = []
		l2 = []
		l = []
		while t:
			if t.data in v1:
				l1.append(t.data)
			else:
				l2.append(t.data)
			t = t.next
		l = l1 + l2
		l.reverse()
		h1 = Node(l[0])
		l.remove(l[0])
		for item in l:
			node = Node(item)
			node.next = h1
			h1 = node
		return h1


class Solution:

	def arrangeCV(self, head):
		v = []
		c = []
		tmp = head
		while tmp:
			if tmp.data in 'aieou':
				v.append(tmp.data)
			else:
				c.append(tmp.data)
			tmp = tmp.next
		tmp = head
		for i in v:
			tmp.data = i
			tmp = tmp.next
		for i in c:
			tmp.data = i
			tmp = tmp.next
		return head


class node:

	def __init__(self, val):
		self.data = val
		self.next = None

class Solution:

	def arrangeCV(self, head):
		temp = head
		vow = None
		cons = None
		while temp:
			if temp.data in ['a', 'e', 'u', 'i', 'o']:
				if vow == None:
					vow = node(temp.data)
					v_temp = vow
				else:
					v_temp.next = node(temp.data)
					v_temp = v_temp.next
			elif cons == None:
				cons = node(temp.data)
				c_temp = cons
			else:
				c_temp.next = node(temp.data)
				c_temp = c_temp.next
			temp = temp.next
		head = vow
		while vow and vow.next:
			vow = vow.next
		if vow:
			vow.next = cons
		else:
			head = cons
		return head


class Solution:

	def arrangeCV(self, head):
		a = []
		res = []
		temp = head
		while temp != None:
			a.append(temp.data)
			temp = temp.next
		for i in a:
			if i in 'aeiou':
				res.append(i)
		for i in a:
			if i not in 'aeiou':
				res.append(i)
		for i in res:
			print(i, end=' ')


class Solution:

	def arrangeCV(self, head):
		ans = ['', '']
		while head != None:
			isV = head.data.lower() not in 'aeiou'
			ans[isV] += head.data
			head = head.next
		ans = ans[0] + ans[1]
		print(*ans, end='')
		return None


class Solution:

	def arrangeCV(self, head):
		vowels = 'aeiou'
		temp = head
		v = []
		c = []
		while temp:
			if temp.data in vowels:
				v.append(temp.data)
			else:
				c.append(temp.data)
			temp = temp.next
		temp = head
		for i in v:
			temp.data = i
			temp = temp.next
		for i in c:
			temp.data = i
			temp = temp.next
		return head


class Solution:

	def arrangeCV(self, head):
		temp = head
		vo = 'a,e,i,o,u'
		vo1 = ''
		co = ''
		while temp:
			if temp.data in vo:
				vo1 += temp.data
			else:
				co += temp.data
			temp = temp.next
		temp = head
		for i in vo1:
			temp.data = i
			temp = temp.next
		for i in co:
			temp.data = i
			temp = temp.next
		return head


class Solution:

	def arrangeCV(self, head):
		co = ''
		vo = ''
		temp = head
		while temp:
			if temp.data in 'aeiou':
				vo += temp.data
			else:
				co += temp.data
			temp = temp.next
		temp = head
		for i in vo:
			temp.data = i
			temp = temp.next
		for i in co:
			temp.data = i
			temp = temp.next
		return head


class Solution:

	def arrangeCV(self, start):
		v = ['a', 'e', 'i', 'o', 'u']
		if start.next is None:
			return start
		if start.data in v:
			temp = start.next
			pos = start
			prev = start
		else:
			temp = start
			pos = None
			prev = None
		while temp:
			if temp.data not in v:
				prev = temp
				temp = temp.next
			else:
				node = Node(temp.data)
				prev.next = temp.next
				temp = prev.next
				if pos is None:
					node.next = start
					start = node
					pos = node
				else:
					node.next = pos.next
					pos.next = node
					pos = node
		return start


class Solution:

	def arrangeCV(self, start):
		vowel = 'aeiouAEIOU'
		vow = ''
		cons = ''
		temp = start
		while temp:
			if temp.data in vowel:
				vow += temp.data
			else:
				cons += temp.data
			temp = temp.next
		temp = start
		i = 0
		while i < len(vow):
			temp.data = vow[i]
			temp = temp.next
			i += 1
		i = 0
		while i < len(cons):
			temp.data = cons[i]
			temp = temp.next
			i += 1
		return start


class Solution:

	def arrangeCV(self, start):
		vow = ['a', 'e', 'i', 'o', 'u']
		res_temp = Node(-1)
		res = res_temp
		temp = start
		while temp:
			if temp.data in vow:
				node = Node(temp.data)
				res_temp.next = node
				res_temp = node
			temp = temp.next
		temp = start
		while temp:
			if temp.data not in vow:
				node = Node(temp.data)
				res_temp.next = node
				res_temp = node
			temp = temp.next
		return res.next


class Solution:

	def arrangeCV(self, head):
		l1 = []
		l2 = []
		while head:
			l1.append(head.data)
			head = head.next
		for i in l1:
			if i in 'aeiou':
				l2.append(i)
		for i in l1:
			if i not in 'aeiou':
				l2.append(i)
		dummy = Node(0)
		no = dummy
		for i in l2:
			no.next = Node(i)
			no = no.next
		return dummy.next


class Solution:

	def arrangeCV(self, head):
		a = []
		b = head
		while b:
			a.append(b.data)
			b = b.next
		h = []
		j = []
		for i in a:
			if i == 'a' or i == 'e' or i == 'i' or (i == 'o') or (i == 'u'):
				h.append(i)
			else:
				j.append(i)
		r = h + j
		w = q = Node(r[0])
		for i in range(1, len(r)):
			w.next = Node(r[i])
			w = w.next
		return q


class Solution:

	def arrangeCV(self, head):
		start = []
		end = []
		vowels = set('aeiou')
		first = head
		while head:
			if str(head.data) in vowels:
				start.append(head.data)
			else:
				end.append(head.data)
			head = head.next
		head = first
		while start:
			head.data = start.pop(0)
			head = head.next
		while head:
			head.data = end.pop(0)
			head = head.next
		return first


class Solution:

	def arrangeCV(self, head):
		s = {'a', 'e', 'i', 'o', 'u'}
		temp = head
		v = ''
		c = ''
		while temp:
			if temp.data.lower() in s:
				v += temp.data
			else:
				c += temp.data
			temp = temp.next
		temp = head
		for i in v:
			temp.data = i
			temp = temp.next
		for i in c:
			temp.data = i
			temp = temp.next
		return head


class Solution:

	def arrangeCV(self, head):
		(res1, res2) = ([], [])
		while head:
			if head.data in 'aeiou':
				res1.append(head.data)
			else:
				res2.append(head.data)
			head = head.next
		temp = Node(0)
		curr = temp
		for i in res1 + res2:
			curr.next = Node(i)
			curr = curr.next
		return temp.next


class Solution:

	def arrangeCV(self, head):
		vowel = ['a', 'e', 'i', 'o', 'u']
		res1 = []
		res2 = []
		while head:
			if head.data in vowel:
				res1.append(head.data)
			else:
				res2.append(head.data)
			head = head.next
		res = res1 + res2
		temp = Node(0)
		curr = temp
		for i in res:
			curr.next = Node(i)
			curr = curr.next
		return temp.next


class Solution:

	def arrangeCV(self, head):
		n1 = []
		n2 = []
		vowels = ['a', 'e', 'i', 'o', 'u']
		while head:
			if head.data in vowels:
				n1.append(head.data)
			else:
				n2.append(head.data)
			head = head.next
		r2 = Linked_List()
		n1 = n1 + n2
		for i in n1:
			r2.insert(i)
		return r2.head


class Solution:

	def arrangeCV(self, head):
		vowels = set('aeiou')
		vowstart = Node(-1)
		vowend = vowstart
		consstart = Node(-1)
		consend = consstart
		while head != None:
			if head.data in vowels:
				vowend.next = Node(head.data)
				vowend = vowend.next
			else:
				consend.next = Node(head.data)
				consend = consend.next
			head = head.next
		vowstart = vowstart.next
		consstart = consstart.next
		if vowstart != None and consstart != None:
			vowend.next = consstart
			return vowstart
		elif consstart != None:
			return consstart
		elif vowstart != None:
			return vowstart
		else:
			return None


class Solution:

	def arrangeCV(self, head):
		v = []
		c = []
		while head:
			if head.data == 'a' or head.data == 'e' or head.data == 'i' or (head.data == 'o') or (head.data == 'u'):
				v.append(head.data)
			else:
				c.append(head.data)
			head = head.next
		num2 = v + c
		r = Linked_List()
		for i in num2:
			r.insert(i)
		return r.head


class Solution:

	def arrangeCV(self, head):
		if head:
			temp = head
			prev = None
			t1 = head
			head2 = None
			tail2 = None
			if head.next:
				while temp:
					if temp.data not in ['a', 'e', 'i', 'o', 'u']:
						if temp == head:
							head = head.next
							temp.next = None
							if head2 == None:
								head2 = temp
								tail2 = temp
							else:
								tail2.next = temp
								tail2 = tail2.next
							temp = head
						else:
							prev.next = temp.next
							temp.next = None
							if head2 == None:
								head2 = temp
								tail2 = temp
							else:
								tail2.next = temp
								tail2 = tail2.next
							temp = prev.next
					else:
						prev = temp
						temp = temp.next
				tail2.next = None
				t = head
				if head:
					while t.next:
						t = t.next
					t.next = head2
					return head
				else:
					return head2
			return head


class Solution:

	def arrangeCV(self, head):
		name1 = set('aeiou')
		list1 = []
		list2 = []
		list3 = []
		list4 = []
		a = head
		while a:
			list1.append(a.data)
			a = a.next
		for i in list1:
			if i in name1:
				list2.append(i)
			else:
				list3.append(i)
		list4 = list2 + list3
		third = Node(list4[0])
		t = third
		for (i, v) in enumerate(list4):
			if i != 0:
				new = Node(v)
				t.next = new
				t = new
		return third


class Solution:

	def arrangeCV(self, head):
		if not head:
			return head
		vow = None
		vowStart = None
		cons = None
		consStart = None
		vowStartFinal = None
		while head:
			if head.data in 'aeiou':
				if vow is None:
					vow = head
					vowStart = vow
					vowStartFinal = vow
				else:
					vow.next = head
					vow = vow.next
			elif not cons:
				cons = head
				consStart = cons
			else:
				cons.next = head
				cons = cons.next
			head = head.next
		if not vowStart:
			return consStart
		if not consStart:
			return vowStart
		vow.next = None
		cons.next = None
		while vowStart.next:
			vowStart = vowStart.next
		vowStart.next = consStart
		return vowStartFinal


class Solution:

	def arrangeCV(self, head):
		v = Linked_List()
		c = Linked_List()
		t = head
		while t != None:
			if t.data == 'a' or t.data == 'e' or t.data == 'i' or (t.data == 'o') or (t.data == 'u'):
				v.insert(t.data)
			else:
				c.insert(t.data)
			t = t.next
		v1 = v.head
		t = head
		while v1 != None:
			t.data = v1.data
			t = t.next
			v1 = v1.next
		c1 = c.head
		while c1 != None:
			t.data = c1.data
			t = t.next
			c1 = c1.next
		return head


class Solution:

	def arrangeCV(self, head):
		s = {'a', 'e', 'i', 'o', 'u'}
		l1 = []
		l2 = []
		temp1 = head
		temp = head
		while temp is not None:
			if temp.data in s:
				l1.append(temp.data)
				temp = temp.next
			else:
				l2.append(temp.data)
				temp = temp.next
		l = l1 + l2
		j = 0
		while temp1 is not None:
			temp1.data = l[j]
			j += 1
			temp1 = temp1.next
		return head


class Solution:

	def arrangeCV(self, head):
		v = ['a', 'e', 'i', 'o', 'u']
		li = []
		h = head
		while h:
			li.append(h.data)
			h = h.next
		h = head
		for i in li:
			if i in v:
				h.data = i
				h = h.next
		for j in li:
			if j not in v:
				h.data = j
				h = h.next
		return head


class Solution:

	def arrangeCV(self, head):
		c = []
		v = []
		curr = head
		while curr is not None:
			if curr.data == 'a' or curr.data == 'e' or curr.data == 'i' or (curr.data == 'o') or (curr.data == 'u'):
				v.append(curr.data)
			else:
				c.append(curr.data)
			curr = curr.next
		(curr, tail) = (None, None)
		while len(v) > 0:
			if curr == None:
				curr = Node(v.pop(0))
				tail = curr
			else:
				tail.next = Node(v.pop(0))
				tail = tail.next
		while len(c) > 0:
			if curr == None:
				curr = Node(c.pop(0))
				tail = curr
			else:
				tail.next = Node(c.pop(0))
				tail = tail.next
		return curr


class Solution:

	def arrangeCV(self, head):
		lv = ['a', 'e', 'i', 'o', 'u']
		temp1 = head
		temp2 = head
		l = []
		while temp1:
			l.append(temp1.data)
			temp1 = temp1.next
		l1 = []
		l2 = []
		for item in l:
			if item in lv:
				l1.append(item)
			else:
				l2.append(item)
		lf = l1 + l2
		for item in lf:
			temp2.data = item
			temp2 = temp2.next
		return head


class Solution:

	def arrangeCV(self, head):
		c = []
		v = []
		temp = head
		while temp:
			x = str(temp.data)
			if x == 'a' or x == 'e' or x == 'i' or (x == 'o') or (x == 'u'):
				v.append(str(x))
			else:
				c.append(str(x))
			temp = temp.next
		v.extend(c)
		l = Linked_List()
		for i in v:
			l.insert(i)
		return l.head


class Solution:

	def arrangeCV(self, head):
		current = head
		vowel = None
		cons = None
		start = None
		start2 = None
		while current != None:
			if current.data.lower() in ('a', 'e', 'i', 'o', 'u'):
				if vowel == None:
					vowel = Node(current.data)
					start = vowel
				else:
					vowel.next = Node(current.data)
					vowel = vowel.next
			elif cons == None:
				cons = Node(current.data)
				start2 = cons
			else:
				cons.next = Node(current.data)
				cons = cons.next
			current = current.next
		if start == None:
			return start2
		vowel.next = start2
		return start


class Solution:

	def arrangeCV(self, head):
		curr = head
		dummy1 = Node(0)
		dummy2 = Node(0)
		F_head = dummy1
		C_head = dummy2
		while curr:
			if curr.data in 'aeiou':
				dummy1.next = Node(curr.data)
				dummy1 = dummy1.next
			else:
				dummy2.next = Node(curr.data)
				dummy2 = dummy2.next
			curr = curr.next
		C_head = C_head.next
		dummy1.next = C_head
		return F_head.next


class Solution:

	def arrangeCV(self, head):
		ov = ''
		nov = ''
		p = head
		while p:
			if p.data == 'a' or p.data == 'e' or p.data == 'i' or (p.data == 'o') or (p.data == 'u'):
				ov += p.data
			else:
				nov += p.data
			p = p.next
		q = head
		for i in ov:
			q.data = i
			q = q.next
		for i in nov:
			q.data = i
			q = q.next
		return head


class Solution:

	def arrangeCV(self, head):

		def isVowel(x):
			return x == 'a' or x == 'e' or x == 'i' or (x == 'o') or (x == 'u') or (x == 'A') or (x == 'E') or (x == 'I') or (x == 'O') or (x == 'U')
		newHead = head
		latestVowel = None
		curr = head
		if head == None:
			return None
		if isVowel(head.data):
			latestVowel = head
		else:
			while curr.next != None and (not isVowel(curr.next.data)):
				curr = curr.next
			if curr.next == None:
				return head
			latestVowel = newHead = curr.next
			curr.next = curr.next.next
			latestVowel.next = head
		while curr != None and curr.next != None:
			if isVowel(curr.next.data):
				if curr == latestVowel:
					latestVowel = curr = curr.next
				else:
					temp = latestVowel.next
					latestVowel.next = curr.next
					latestVowel = latestVowel.next
					curr.next = curr.next.next
					latestVowel.next = temp
			else:
				curr = curr.next
		return newHead


class Solution:

	def arrangeCV(self, head):
		vowels = Node('-1')
		vp = vowels
		consonents = Node('-1')
		cp = consonents
		while head != None:
			if head.data in 'aeiou':
				vp.next = head
				vp = vp.next
			else:
				cp.next = head
				cp = cp.next
			head = head.next
		cp.next = None
		vp.next = consonents.next
		return vowels.next


def insert(head, n):
	if head == None:
		head = n
	else:
		n.next = head
		head = n
	return head

class Solution:

	def arrangeCV(self, head):
		vowels = []
		consonants = []
		temp = head
		while temp != None:
			if temp.data == 'a' or temp.data == 'e' or temp.data == 'i' or (temp.data == 'o') or (temp.data == 'u'):
				vowels.append(temp.data)
			else:
				consonants.append(temp.data)
			temp = temp.next
		vowels = vowels[::-1]
		consonants = consonants[::-1]
		consonants = consonants + vowels
		head = None
		for i in consonants:
			newnode = Node(i)
			head = insert(head, newnode)
		return head


class Solution:

	def arrangeCV(self, head):
		j = ''
		st = ''
		k = ''
		itr = head
		while itr:
			k += itr.data
			itr = itr.next
		for i in range(len(k)):
			if k[i] == 'a' or k[i] == 'e' or k[i] == 'i' or (k[i] == 'o') or (k[i] == 'u'):
				st += k[i]
			else:
				j += k[i]
		st += j
		temp = head
		i = 0
		while temp != None:
			temp.data = st[i]
			i += 1
			temp = temp.next
		return head


class Solution:

	def arrangeCV(self, head):
		from collections import deque
		dq = deque()
		dq1 = deque()
		current = head
		while current != None:
			if current.data == 'a' or current.data == 'e' or current.data == current.data == 'i' or (current.data == 'o') or (current.data == 'u'):
				dq.append(current.data)
			else:
				dq1.append(current.data)
			current = current.next
		current1 = head
		while current1 != None and len(dq) != 0:
			current1.data = dq.popleft()
			current1 = current1.next
		while current1 != None and len(dq1) != 0:
			current1.data = dq1.popleft()
			current1 = current1.next
		return head


class Solution:

	def arrangeCV(self, head):
		if head is None:
			return head
		if head.next is None:
			return head
		vowels = ['a', 'e', 'i', 'o', 'u']
		d1 = Node(None)
		d2 = Node(None)
		tail1 = d1
		tail2 = d2
		while head is not None:
			if head.data in vowels:
				tail1.next = head
				tail1 = tail1.next
			else:
				tail2.next = head
				tail2 = tail2.next
			head = head.next
		tail1.next = None
		tail2.next = None
		v_head = d1.next
		c_head = d2.next
		if v_head is None:
			return c_head
		if c_head is None:
			return v_head
		tail1.next = c_head
		return v_head


class Solution:

	def arrangeCV(self, head):
		v = []
		c = []
		vd = set(['a', 'e', 'i', 'o', 'u'])
		while head:
			if head.data in vd:
				v.append(head.data)
			else:
				c.append(head.data)
			head = head.next
		ans = Linked_List()
		for i in v:
			ans.insert(i)
		for i in c:
			ans.insert(i)
		return ans.head


class Solution:

	def arrangeCV(self, head):
		vowel = ('a', 'e', 'i', 'o', 'u')
		st1 = st2 = v = c = None
		while head:
			if head.data in vowel:
				if not v:
					v = st1 = head
				else:
					v.next = head
					v = head
			elif not c:
				c = st2 = head
			else:
				c.next = head
				c = head
			head = head.next
		if st1:
			if st2:
				v.next = st2
				c.next = None
			return st1
		else:
			return st2


class Solution:

	def arrangeCV(self, head):
		newList1 = Linked_List()
		newList2 = Linked_List()
		if head:
			vowels = ['a', 'e', 'i', 'o', 'u']
			temp = head
			while temp:
				if temp.data in vowels:
					newList1.insert(temp.data)
				else:
					newList2.insert(temp.data)
				temp = temp.next
			if newList1.head is None:
				return newList2.head
			elif newList2.head is None:
				return newList1.head
			else:
				newList1.tail.next = newList2.head
			return newList1.head


class Solution:

	def arrangeCV(self, head):
		v = ['a', 'e', 'i', 'o', 'u']
		u = []
		k = []
		root = head
		s = head
		while root:
			if root.data in v:
				k.append(root.data)
			else:
				u.append(root.data)
			root = root.next
		final = k + u
		x = 0
		while s:
			s.data = final[x]
			x = x + 1
			s = s.next
		return head


class Solution:

	def arrangeCV(self, head):
		c = []
		v = []
		vowels = ['a', 'e', 'i', 'o', 'u']
		curr = head
		while curr:
			if curr.data in vowels:
				v.append(curr.data)
			else:
				c.append(curr.data)
			curr = curr.next
		final = v + c
		curr = head
		i = 0
		head = curr
		while curr:
			curr.data = final[i]
			i += 1
			curr = curr.next
		return head


class Solution:

	def arrangeCV(self, head):
		v = ''
		c = ''
		x = 'aeiou'
		while head:
			a = head.data
			if a in x:
				v += a
			else:
				c += a
			head = head.next
		ans = v + c
		for i in ans:
			print(i, end=' ')


class Solution:

	def arrangeCV(self, head):
		oval = ['a', 'e', 'i', 'o', 'u']
		(o, c) = ([], [])
		t = head
		while t:
			if t.data in oval:
				o.append(t.data)
			else:
				c.append(t.data)
			t = t.next
		t = head
		for i in o:
			t.data = i
			t = t.next
		for i in c:
			t.data = i
			t = t.next
		return head


class Solution:

	def arrangeCV(self, head):
		dummy = Node('0')
		cons = dummy
		tmp = head
		d1 = Node('0')
		d1.next = head
		prev = d1
		while tmp:
			if tmp.data not in 'aeiou':
				cons.next = tmp
				cons = cons.next
			else:
				prev.next = tmp
				prev = tmp
			tmp = tmp.next
		prev.next = None
		cons.next = None
		prev.next = dummy.next
		return d1.next


class Solution:

	def arrangeCV(self, head):
		vowels = []
		consonants = []
		temp = head
		while temp != None:
			if temp.data in ['a', 'e', 'i', 'o', 'u']:
				vowels.append(temp)
			else:
				consonants.append(temp)
			temp = temp.next
		nodes = vowels + consonants
		head = nodes[0]
		for i in range(len(nodes) - 1):
			nodes[i].next = nodes[i + 1]
		nodes[-1].next = None
		return head


class Solution:

	def arrangeCV(self, head):
		vowels = []
		consonants = []
		temp = head
		while temp != None:
			if temp.data in ['a', 'e', 'i', 'o', 'u']:
				vowels.append(temp)
			else:
				consonants.append(temp)
			temp = temp.next
		nodes = vowels + consonants
		head = nodes[0]
		for i in range(len(nodes) - 1):
			nodes[i].next = nodes[i + 1]
		nodes[-1].next = None
		return head

class Node:

	def __init__(self, val):
		self.data = val
		self.next = None

class Linked_List:

	def __init__(self):
		self.head = None
		self.tail = None

	def insert(self, val):
		if self.head is None:
			self.head = Node(val)
			self.tail = self.head
		else:
			self.tail.next = Node(val)
			self.tail = self.tail.next

def printList(head):
	tmp = head
	while tmp:
		print(tmp.data, end=' ')
		tmp = tmp.next
	print()
if __name__ == '__main__':
	for i in range(int(input())):
		n = int(input())
		arr = [str(x) for x in input().split()]
		lis = Linked_List()
		for i in arr:
			lis.insert(i)
		newHead = Solution().arrangeCV(lis.head)
		printList(newHead)


class Solution:

	def arrangeCV(self, head):
		vowel = Node(-1)
		cons = Node(-1)
		vo = vowel
		co = cons
		temp = head
		v = ['a', 'e', 'i', 'o', 'u']
		while temp:
			key = temp.data
			nde = Node(key)
			if key in v:
				vowel.next = nde
				vowel = nde
			else:
				cons.next = nde
				cons = nde
			temp = temp.next
		vowel.next = co.next
		return vo.next

class Node:

	def __init__(self, val):
		self.data = val
		self.next = None

class Linked_List:

	def __init__(self):
		self.head = None
		self.tail = None

	def insert(self, val):
		if self.head is None:
			self.head = Node(val)
			self.tail = self.head
		else:
			self.tail.next = Node(val)
			self.tail = self.tail.next

def printList(head):
	tmp = head
	while tmp:
		print(tmp.data, end=' ')
		tmp = tmp.next
	print()
if __name__ == '__main__':
	for i in range(int(input())):
		n = int(input())
		arr = [str(x) for x in input().split()]
		lis = Linked_List()
		for i in arr:
			lis.insert(i)
		newHead = Solution().arrangeCV(lis.head)
		printList(newHead)


class Solution:

	def arrangeCV(self, head):
		if head == None or head.next == None:
			return head
		conso_head = None
		conso_ptr = None
		vowel_head = None
		vowel_ptr = None
		itr = head
		vowels = ['a', 'e', 'i', 'o', 'u']
		while itr:
			if itr.data not in vowels:
				if not conso_head:
					conso_head = itr
					conso_ptr = conso_head
				else:
					conso_ptr.next = itr
					conso_ptr = conso_ptr.next
			elif not vowel_head:
				vowel_head = itr
				vowel_ptr = vowel_head
			else:
				vowel_ptr.next = itr
				vowel_ptr = vowel_ptr.next
			itr = itr.next
		if vowel_ptr:
			if conso_head:
				vowel_ptr.next = conso_head
				conso_ptr.next = None
			else:
				vowel_ptr.next = conso_head
			return vowel_head
		else:
			conso_ptr.next = None
			return conso_head

class Node:

	def __init__(self, val):
		self.data = val
		self.next = None

class Linked_List:

	def __init__(self):
		self.head = None
		self.tail = None

	def insert(self, val):
		if self.head is None:
			self.head = Node(val)
			self.tail = self.head
		else:
			self.tail.next = Node(val)
			self.tail = self.tail.next

def printList(head):
	tmp = head
	while tmp:
		print(tmp.data, end=' ')
		tmp = tmp.next
	print()
if __name__ == '__main__':
	for i in range(int(input())):
		n = int(input())
		arr = [str(x) for x in input().split()]
		lis = Linked_List()
		for i in arr:
			lis.insert(i)
		newHead = Solution().arrangeCV(lis.head)
		printList(newHead)


class Solution:

	def arrangeCV(self, head):
		vowel = []
		const = []
		itr = head
		while itr:
			if itr.data == 'a' or itr.data == 'e' or itr.data == 'i' or (itr.data == 'o') or (itr.data == 'u'):
				vowel.append(itr.data)
				itr = itr.next
			else:
				const.append(itr.data)
				itr = itr.next
		itr = head
		i = 0
		while i < len(vowel):
			itr.data = vowel[i]
			i += 1
			itr = itr.next
		j = 0
		while j < len(const):
			itr.data = const[j]
			j += 1
			itr = itr.next
		return head

class Node:

	def __init__(self, val):
		self.data = val
		self.next = None

class Linked_List:

	def __init__(self):
		self.head = None
		self.tail = None

	def insert(self, val):
		if self.head is None:
			self.head = Node(val)
			self.tail = self.head
		else:
			self.tail.next = Node(val)
			self.tail = self.tail.next

def printList(head):
	tmp = head
	while tmp:
		print(tmp.data, end=' ')
		tmp = tmp.next
	print()
if __name__ == '__main__':
	for i in range(int(input())):
		n = int(input())
		arr = [str(x) for x in input().split()]
		lis = Linked_List()
		for i in arr:
			lis.insert(i)
		newHead = Solution().arrangeCV(lis.head)
		printList(newHead)


class node:

	def __init__(self, val):
		self.data = val
		self.next = None

class Solution:

	def arrangeCV(self, head):
		vowels = ['a', 'e', 'i', 'o', 'u']
		temp = Linked_List()
		vow_list = []
		no_vow_list = []
		while head is not None:
			if head.data in vowels:
				vow_list.append(head.data)
			else:
				no_vow_list.append(head.data)
			head = head.next
		list = vow_list + no_vow_list
		for el in list:
			temp.insert(el)
		return temp.head


class Solution:

	def arrangeCV(self, head):
		arr = []
		while head:
			arr.append(head.data)
			head = head.next
		vowel = ['a', 'i', 'e', 'o', 'u']
		ans1 = []
		ans2 = []
		for i in arr:
			if i in vowel:
				ans1.append(i)
			else:
				ans2.append(i)
		result = ans1 + ans2
		ll = Linked_List()
		for i in result:
			ll.insert(i)
		return ll.head


class Solution:

	def arrangeCV(self, head):
		vowels = ['a', 'e', 'i', 'o', 'u']
		head_vowels = None
		head_others = None
		temp = head
		while temp is not None:
			letter = str(temp.data)
			if letter not in vowels:
				if head_others is None:
					head_others = temp
					tail_others = temp
				else:
					tail_others.next = temp
					tail_others = temp
			elif head_vowels is None:
				head_vowels = temp
				tail_vowels = temp
			else:
				tail_vowels.next = temp
				tail_vowels = temp
			temp = temp.next
		if head_vowels is None or head_others is None:
			return head
		tail_vowels.next = head_others
		tail_others.next = None
		return head_vowels


class Solution:

	def arrangeCV(self, head):
		c = 'aeiouAEIOU'
		cons = []
		vow = []
		curr = head
		ans = head
		while head:
			g = head.data
			if g in c:
				vow.append(g)
			else:
				cons.append(g)
			head = head.next
		i = 0
		while len(vow) > i:
			curr.data = vow[i]
			i = i + 1
			curr = curr.next
		i = 0
		while len(cons) > i:
			curr.data = cons[i]
			i = i + 1
			curr = curr.next
		return ans


class Solution:

	def arrangeCV(self, head):
		vowel = ['a', 'e', 'i', 'o', 'u']
		num = []
		num1 = []
		t = head
		while t:
			if t.data in vowel:
				num.append(t.data)
			else:
				num1.append(t.data)
			t = t.next
		num2 = num + num1
		r = Linked_List()
		for i in num2:
			r.insert(i)
		return r.head
		c = Node(None)
		v = Node(None)
		a = v
		vowel = 'aeiou'
		temp = head
		while temp and temp.next:
			if temp.data in vowel:
				v.next = temp
				v = v.next
			else:
				c.next = temp
				c = c.next
			head = head.next
		v.next = c.next
		return a.next


class Solution:

	def arrangeCV(self, head):
		(vowels, consonents) = ('', '')
		current = head
		while current:
			if current.data in 'aeiou':
				vowels += current.data
			else:
				consonents += current.data
			current = current.next
		value = vowels + consonents
		ptr = head
		for i in value:
			ptr.data = i
			ptr = ptr.next
		return head


class Solution:

	def arrangeCV(self, head):
		const_start = None
		const_end = None
		vow_start = None
		vow_end = None
		stri = 'aeiou'
		curr = head
		while curr is not None:
			val = curr.data
			if val in stri:
				if vow_start is None:
					vow_start = curr
					vow_end = vow_start
				else:
					vow_end.next = curr
					vow_end = vow_end.next
			elif const_start is None:
				const_start = curr
				const_end = const_start
			else:
				const_end.next = curr
				const_end = const_end.next
			curr = curr.next
		if const_start is None or vow_start is None:
			return head
		head = vow_start
		vow_end.next = const_start
		const_end.next = None
		return head


class Solution:

	def arrangeCV(self, head):
		vow = None
		con = None
		while head:
			if head.data in 'aeiou':
				if vow:
					vow_end.next = head
					vow_end = vow_end.next
				else:
					vow = head
					vow_end = head
			elif con:
				con_end.next = head
				con_end = con_end.next
			else:
				con = head
				con_end = head
			head = head.next
		if vow:
			vow_end.next = con
			if con:
				con_end.next = None
			return vow
		return con


class Solution:

	def arrangeCV(self, head):
		vowels = ['a', 'e', 'i', 'o', 'u']
		(vowels1, consonents) = ([], [])
		ll = Linked_List()
		itr = head
		while itr:
			if itr.data in vowels:
				vowels1.append(itr.data)
			else:
				consonents.append(itr.data)
			itr = itr.next
		for i in vowels1 + consonents:
			ll.insert(i)
		return ll.head


class Solution:

	def arrangeCV(self, head):
		if head is None:
			return head
		vowels = ['a', 'e', 'u', 'i', 'o']
		lst1 = []
		lst2 = []
		tmp = head
		while tmp:
			if tmp.data in vowels:
				lst1.append(tmp.data)
			else:
				lst2.append(tmp.data)
			tmp = tmp.next
		lst = lst1 + lst2
		head1 = Node(-1)
		tmp = head1
		for i in range(len(lst)):
			tmp.next = Node(lst[i])
			tmp = tmp.next
		head1 = head1.next
		return head1


class Solution:

	def arrangeCV(self, head):
		v = []
		c = []
		while head:
			if head.data in ['a', 'e', 'i', 'o', 'u']:
				v.append(head.data)
				head = head.next
			else:
				c.append(head.data)
				head = head.next
		res = v + c
		l = Linked_List()
		for i in res:
			l.insert(i)
		return l.head


class Solution:

	def arrangeCV(self, head):
		arr = []
		brr = []
		curr = head
		while curr != None:
			if curr.data == 'a' or curr.data == 'i' or curr.data == 'o' or (curr.data == 'u') or (curr.data == 'e'):
				arr.append(curr.data)
			else:
				brr.append(curr.data)
			curr = curr.next
		curr = head
		for i in range(0, len(arr)):
			curr.data = arr[i]
			curr = curr.next
		for i in range(0, len(brr)):
			curr.data = brr[i]
			curr = curr.next
		return head


class Solution:

	def arrangeCV(self, head):
		vowels = ['a', 'e', 'i', 'o', 'u']
		s = head
		v = []
		c = []
		s2 = head
		res = head
		while s != None:
			if s.data in vowels:
				v.append(s.data)
			else:
				c.append(s.data)
			s = s.next
		for i in v:
			s2.data = i
			s2 = s2.next
		for i in c:
			s2.data = i
			s2 = s2.next
		return res


class node:

	def __init__(self, val):
		self.data = val
		self.next = None

class Solution:

	def arrangeCV(self, head):
		Str = 'aeiou'
		Vow = []
		Con = []
		while head:
			if head.data in Str:
				Vow.append(head.data)
				head = head.next
			else:
				Con.append(head.data)
				head = head.next
		temp = Vow + Con
		for i in temp:
			print(i, end=' ')


class Solution:

	def arrangeCV(self, head):
		x = {'a', 'e', 'i', 'o', 'u'}
		y = []
		z = []
		while head:
			if head.data in x:
				y.append(head.data)
			else:
				z.append(head.data)
			head = head.next
		y.extend(z)
		m = Node(y[0])
		n = m
		for i in range(1, len(y)):
			new = Node(y[i])
			n.next = new
			n = new
		return m