Given a singly linked list of 0s and 1s, the task is to find its decimal equivalent. Decimal Value of an empty linked list is considered as 0.
Since the answer can be very large, answer modulo 1000000007 should be printed.
Input:
First line of input contains number of testcases T. For each testcase, first line of input contains 
Output:
The function should return should decimal equivalent modulo 1000000007.
User Task:
The task is to complete the function decimalValue() which should find the decimal value of the given binary value in the linked list.
Constraints:
1 <= T <= 200
0 <= N <= 100
Data of Node is either 0 or 1
Example:
Input:
2
3
0 1 1    
4
1 1 1 0
Output:
3
14
Explanation:
Testcase 1: 1*2^{0} + 1*2^{1} + 0*2^{2} =  1 + 2 + 0 = 3.

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: # your task is to complete this function

# Function should return an integer value



'''

class node:

    def __init__(self):

        self.data = None

        self.next = None

'''



def decimalValue(head):

    MOD=10**9+7

    # Code here

Solutions:
def decimalValue(head):
	MOD = 10 ** 9 + 7
	itr = 0
	temp = head
	out = 0
	while temp != None:
		itr = itr + 1
		temp = temp.next
	temp = head
	itr1 = -1
	while temp != None:
		out = out + temp.data * 2 ** (itr + itr1)
		itr1 = itr1 - 1
		temp = temp.next
	return out % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	bi = ''
	while head:
		bi += str(head.data)
		head = head.next
	num = int(bi, 2) % MOD
	return num


def decimalValue(head):
	if head == None:
		return 0
	s = ''
	while head != None:
		s += str(head.data)
		head = head.next
	res = 0
	j = 0
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			res = (res + 2 ** j) % (10 ** 9 + 7)
		j += 1
	return res


def decimalValue(head):
	MOD = 10 ** 9 + 7
	s = ''
	n = head
	while n is not None:
		s = str(n.data) + s
		n = n.next
	res = 0
	for i in range(0, len(s)):
		res = res + int(s[i]) * pow(2, i)
	return res % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	a = head
	p = []
	while a is not None:
		p.append(str(a.data))
		a = a.next
	m = int(''.join(p))
	s = 0
	i = 0
	while m != 0:
		rem = m % 10
		s = s + rem * 2 ** i
		m //= 10
		i += 1
	return s % (10 ** 9 + 7)


def decimalValue(head):
	MOD = 10 ** 9 + 7
	s = ''
	while head:
		s += str(head.data)
		head = head.next
	return int(s, 2) % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	count = 0
	temp = head
	while temp:
		count += 1
		temp = temp.next
	current = head
	result = 0
	count -= 1
	while current:
		result += current.data * 2 ** count
		count -= 1
		current = current.next
	result = result % MOD
	return result


def decimalValue(head):
	MOD = 10 ** 9 + 7
	a = ''
	temp = head
	while temp != None:
		a += str(temp.data)
		temp = temp.next
	return int(a, 2) % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	sec_head = head
	l = 1
	while sec_head.next:
		l += 1
		sec_head = sec_head.next
	sum_ = 0
	while head.next:
		sum_ += head.data * 2 ** (l - 1)
		l -= 1
		head = head.next
	sum_ += head.data
	return sum_ % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	ans = 0
	ptr = head
	while ptr:
		ans = ans * 2 + ptr.data
		ptr = ptr.next
	return ans % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	stack = [head]
	binNum = []
	decNum = 0
	index = 0
	while len(stack) > 0:
		current = stack.pop()
		binNum.append(current.data)
		if current.next:
			stack.append(current.next)
	binNum.reverse()
	for num in binNum:
		decNum += num * 2 ** index
		index += 1
	return decNum % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	t = head
	s = ''
	while t:
		s = s + str(t.data)
		t = t.next
	ans = int(s)
	i = sum = 0
	while ans != 0:
		x = ans % 10
		sum = sum + x * 2 ** i
		i += 1
		ans = ans // 10
	return sum % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	ans = 0
	while head:
		ans = (ans << 1) + head.data
		head = head.next
	return ans % MOD


def decimalValue(head):
	s = ''
	tmp = head
	while tmp:
		s += str(tmp.data)
		tmp = tmp.next
	return int(s, 2) % 1000000007


def decimalValue(head):
	MOD = 10 ** 9 + 7
	curr = head
	size = 0
	while curr:
		size += 1
		curr = curr.next
	curr = head
	ans = 0
	while curr:
		ans += curr.data * 2 ** (size - 1)
		curr = curr.next
		size = size - 1
	return ans % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	curr = head
	l = []
	while curr:
		l.append(curr.data)
		curr = curr.next
	x = 0
	for i in l:
		x = x * 10 + i
	return int(str(x), 2) % MOD


def decimalValue(head):
	mod = 10 ** 9 + 7
	s = ''
	temp = head
	while temp:
		s += str(temp.data)
		temp = temp.next
	return int(s, 2) % mod


def decimalValue(head):
	MOD = 10 ** 9 + 7
	res = 0
	while head:
		res = res * 2 % MOD + head.data
		head = head.next
	return res


def decimalValue(head):
	MOD = 10 ** 9 + 7
	arr = []
	ans = 0
	curr = head
	while curr:
		arr.append(curr.data)
		curr = curr.next
	arr = arr[::-1]
	for (count, elm) in enumerate(arr):
		ans += elm * 2 ** count
	return ans % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	curr = head
	count = 0
	while curr:
		count += 1
		curr = curr.next
	temp = head
	(count, ans) = (count - 1, 0)
	while temp:
		ans += temp.data * pow(2, count)
		count -= 1
		temp = temp.next
	return ans % MOD


def solve(head):
	x = 0
	while head:
		x = x * 10 + head.data
		head = head.next
	return int(str(x), 2)

def decimalValue(head):
	MOD = 10 ** 9 + 7
	a = solve(head)
	return a % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	c = 0
	temp = head
	while temp != None:
		c += 1
		temp = temp.next
	c = c - 1
	s = 0
	temp = head
	while temp != None:
		s += temp.data * 2 ** c
		c -= 1
		temp = temp.next
	return s % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	count = 0
	temp = head
	while temp:
		count += 1
		temp = temp.next
	temp = head
	sum = 0
	for i in range(count - 1, -1, -1):
		sum += 2 ** i * temp.data % MOD
		temp = temp.next
	return sum % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	s = []
	curr = head
	while curr:
		s.append(curr.data)
		curr = curr.next
	s = s[::-1]
	res = 0
	for i in range(len(s)):
		if s[i] == 1:
			res += 2 ** i
	return res % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	c = ''
	while head is not None:
		c = c + str(head.data)
		head = head.next
	c = list(c)
	c = c[::-1]
	c = ''.join(c)
	t = 0
	for i in range(len(c)):
		t = t + int(c[i]) * 2 ** i
	return t % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	curr = head
	piche = None
	while curr:
		aage = curr.next
		curr.next = piche
		piche = curr
		curr = aage
	multi = 0
	s = 0
	while piche:
		s = s + piche.data * 2 ** multi
		multi += 1
		piche = piche.next
	return s % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	if head is None:
		return 0
	currentNode = head
	ans = 0
	while currentNode:
		temp = currentNode.data
		ans *= 2
		if temp > 0:
			ans += 1
		currentNode = currentNode.next
	return ans % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7

	def reverse(head):
		if head == None:
			return head
		prev = None
		curr = head
		while curr != None:
			nex = curr.next
			curr.next = prev
			prev = curr
			curr = nex
		return prev
	rev = reverse(head)
	ans = 0
	count = 0
	temp = rev
	while temp != None:
		ans += temp.data * 2 ** count
		count += 1
		temp = temp.next
	return ans % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	ans = 0
	temp = head
	c = 0
	while temp is not None:
		temp = temp.next
		c += 1
	temp = head
	c = c - 1
	while temp is not None:
		ans = ans + temp.data * 2 ** c
		c -= 1
		temp = temp.next
	return ans % MOD


def decimalValue(start):
	MOD = 10 ** 9 + 7
	count = 0
	temp = start
	while temp:
		count += 1
		temp = temp.next
	count -= 1
	res = 0
	temp = start
	while temp:
		res += temp.data * 2 ** count
		count -= 1
		temp = temp.next
	return res % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	s = ''
	if not head:
		return 0
	while head:
		s += str(head.data)
		head = head.next
	return int(s, 2) % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	sum = ''
	ptr = head
	while ptr:
		sum += str(ptr.data)
		ptr = ptr.next
	num = int(sum, 2) % MOD
	return num


def decimalValue(head):
	MOD = 10 ** 9 + 7

	def reverse(start):
		curr = start
		prev = None
		while curr != None:
			temp = curr.next
			curr.next = prev
			prev = curr
			curr = temp
		return prev
	revhead = reverse(head)
	res = 0
	i = 0
	while revhead != None:
		res = (res % MOD + revhead.data * 2 ** i % MOD) % MOD
		revhead = revhead.next
		i = i + 1
	return res


def decimalValue(head):
	MOD = 10 ** 9 + 7
	ans = []
	while head != None:
		ans.append(str(head.data))
		head = head.next
	x = ''.join(ans)
	x = int(x, 2)
	return x % MOD


def decimalValue(head):
	bi = ''
	while head:
		bi += str(head.data)
		head = head.next
	num = int(bi, 2) % 1000000007
	return num


def decimalValue(head):
	MOD = 10 ** 9 + 7
	s = ''
	p = head
	if head == None:
		return 0
	while p != None:
		s += str(p.data)
		p = p.next
	c = 0
	s = int(s)
	i = 0
	while s > 0:
		x = s % 10
		c += x * pow(2, i)
		s = s // 10
		i += 1
	return c % MOD


def decimalValue(head):
	l = []
	while head:
		l.append(head.data)
		head = head.next
	i = 0
	result = 0
	while l:
		result += 2 ** i * l.pop()
		i += 1
	MOD = 10 ** 9 + 7
	return result % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7

	def length(head):
		cnt = 0
		while head:
			cnt += 1
			head = head.next
		return cnt
	leng = length(head) - 1
	res = 0
	cur = head
	while cur:
		res += cur.data * 2 ** leng
		cur = cur.next
		leng -= 1
		res %= MOD
	return res


def decimalValue(head):
	MOD = 10 ** 9 + 7
	s = ''
	while head:
		s += str(head.data)
		head = head.next
	return eval('0b' + s) % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	ptr = head
	num = 0
	head = reverse(head)
	ptr = head
	count = 0
	while ptr is not None:
		num += ptr.data * 2 ** count
		count += 1
		ptr = ptr.next
	return num % MOD

def reverse(head):
	past = head
	current = head.next
	past.next = None
	while current is not None:
		head = current
		current = current.next
		head.next = past
		past = head
	return head


def decimalValue(head):
	MOD = 10 ** 9 + 7
	p = head
	l = 0
	while p:
		p = p.next
		l += 1
	cur = head
	ans = 0
	while cur:
		ans += cur.data * 2 ** (l - 1)
		cur = cur.next
		l -= 1
	return ans % 1000000007


def decimalValue(head):
	answer = 0
	while head:
		answer = 2 * answer + head.data
		head = head.next
	return answer % (10 ** 9 + 7)


def decimalValue(head):
	MOD = 10 ** 9 + 7
	head = reverse(head)
	num = 0
	i = 0
	while head:
		t = head.data
		num = num + t * 2 ** i
		i += 1
		num = num % MOD
		head = head.next
	return num

def reverse(head):
	if not head or not head.next:
		return head
	prev = None
	while head:
		temp = head
		head = head.next
		temp.next = prev
		prev = temp
	return temp


def decimalValue(head):
	MOD = 10 ** 9 + 7
	s1 = ''
	p = head
	while p:
		s1 += str(p.data)
		p = p.next
	return int(s1, 2) % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	prev = None
	curr = head
	while curr:
		nxt = curr.next
		curr.next = prev
		prev = curr
		curr = nxt
	head = prev
	curr = head
	result = 0
	i = 0
	while curr:
		result += int(curr.data * 2 ** i)
		curr = curr.next
		i += 1
	return result % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	ptr = head
	c = 0
	while ptr != None:
		c += 1
		ptr = ptr.next
	ans = 0
	ptr = head
	while ptr != None:
		ans += ptr.data * 2 ** (c - 1)
		ptr = ptr.next
		c -= 1
	return ans % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7

	def reverse(start):
		curr = start
		prev = None
		while curr:
			(curr.next, prev, curr) = (prev, curr, curr.next)
		return prev
	rhead = reverse(head)
	num = 0
	pos = 0
	while rhead:
		num = (num % MOD + rhead.data * 2 ** pos % MOD) % MOD
		rhead = rhead.next
		pos += 1
	return num


def decimalValue(head):
	MOD = 10 ** 9 + 7
	t = head
	d = None
	while t != None:
		n = t.next
		t.next = d
		d = t
		t = n
	head = d
	i = 0
	sum = 0
	while d != None:
		sum = (sum + d.data * 2 ** i) % 1000000007
		i = i + 1
		d = d.next
	return sum


def count(head):
	c = 0
	temp = head
	while temp:
		c += 1
		temp = temp.next
	return c

def decimalValue(head):
	MOD = 10 ** 9 + 7
	if head:
		a = count(head)
		a1 = a - 1
		sum = 0
		temp = head
		while temp:
			sum += temp.data * 2 ** a1
			a1 -= 1
			temp = temp.next
		return sum % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	bits = 0
	while head:
		bits *= 10
		bits += head.data
		head = head.next
	ct = 0
	ans = 0
	while bits:
		bit = bits & 1
		if bit:
			ans = (ans + 2 ** ct % MOD) % MOD
		ct += 1
		bits //= 10
	return ans


def decimalValue(head):
	MOD = 10 ** 9 + 7
	res = [0]
	power = [0]

	def dfs(node):
		if not node:
			return
		dfs(node.next)
		res[0] += node.data * 2 ** power[0]
		power[0] += 1
		return
	dfs(head)
	return res[0] % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	arr = []
	while head:
		arr.append(head.data)
		head = head.next
	num = 0
	arr = arr[::-1]
	for i in range(len(arr)):
		num += 2 ** i * arr[i]
	return num % MOD


def reverse(head):
	prev = None
	curr = head
	while curr:
		nxt = curr.next
		curr.next = prev
		prev = curr
		curr = nxt
	return prev

def decimalValue(head):
	MOD = 10 ** 9 + 7
	head = reverse(head)
	i = res = 0
	while head:
		res = res + head.data * 2 ** i
		i += 1
		head = head.next
	return res % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	temp = head
	binary = 0
	c = 0
	res = []
	while temp:
		res.append(temp.data)
		temp = temp.next
	for i in range(len(res)):
		if res.pop() == 1:
			binary += 2 ** c
		c += 1
	return binary % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7

	def rev(head):
		curr = head
		prev = None
		while curr:
			temp = curr.next
			curr.next = prev
			prev = curr
			curr = temp
		return prev
	revhead = rev(head)
	temp = revhead
	temp1 = revhead
	count = 0
	num = 0
	while temp1 is not None:
		count += 1
		temp1 = temp1.next
	for i in range(count):
		if temp.data == 0:
			temp = temp.next
		else:
			num = num + 2 ** i
			temp = temp.next
	ans = num % MOD
	return ans


def rev(head):
	nextn = head.next
	prev = head
	while nextn:
		cur = nextn.next
		nextn.next = prev
		prev = nextn
		nextn = cur
	return prev

def decimalValue(head):
	MOD = 10 ** 9 + 7
	temp = head
	l = []
	while temp:
		l.append(temp.data)
		temp = temp.next
	l1 = l[::-1]
	c = 0
	res = 0
	for i in l1:
		res += i * 2 ** c
		c += 1
	return res % 1000000007


def decimalValue(head):
	MOD = 10 ** 9 + 7
	curr = head
	decimal = 0
	while curr:
		decimal = decimal * 2 + curr.data
		curr = curr.next
	return decimal % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	temp = head
	c = 0
	while temp:
		c += 1
		temp = temp.next
	curr = head
	res = 0
	while curr:
		res += curr.data * 2 ** (c - 1)
		curr = curr.next
		c = c - 1
	return res % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7

	def reverse(head):
		if head == None:
			return
		currNode = head
		prev = None
		while currNode != None:
			nxt = currNode.next
			currNode.next = prev
			prev = currNode
			currNode = nxt
		return prev
	if head == None:
		return head
	t = reverse(head)
	ans = 0
	i = 0
	while t != None:
		ans = (ans % MOD + t.data % MOD * 2 ** i % MOD % MOD) % MOD
		i += 1
		t = t.next
	return ans


def decimalValue(head):
	MOD = 10 ** 9 + 7
	num = 0
	while head is not None:
		num *= 2
		num += head.data
		num = num % MOD
		head = head.next
	return num


def decimalValue(head):
	MOD = 10 ** 9 + 7
	cnt = 0
	ptr = head
	decimal = 0
	while ptr != None:
		cnt += 1
		ptr = ptr.next
	ptr = head
	while ptr != None:
		decimal += ptr.data * pow(2, cnt - 1)
		ptr = ptr.next
		cnt -= 1
	return decimal % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	length = 0
	if head is not None:
		temp = head
		while temp is not None:
			length += 1
			temp = temp.next
	length -= 1
	result = 0
	temp = head
	while length >= 0:
		result += temp.data * pow(2, length)
		length -= 1
		temp = temp.next
	return result % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	x = ''
	while head != None:
		x = x + str(head.data)
		head = head.next
	a = len(x) - 1
	b = 0
	for i in range(0, len(x)):
		b = b + int(x[i]) * 2 ** a
		a = a - 1
	return b % MOD


import math

def decimalValue(head):
	MOD = 10 ** 9 + 7
	n = 0
	temp = head
	while temp:
		n += 1
		temp = temp.next
	n -= 1
	ans = 0
	while head and n >= 0:
		ans = ans + head.data * 2 ** n
		n -= 1
		head = head.next
	return int(ans % MOD)


def decimalValue(head):
	MOD = 10 ** 9 + 7
	leni = 0
	itr = head
	while itr:
		leni += 1
		itr = itr.next
	itr = head
	(numi, count) = (0, 0)
	while itr:
		numi += itr.data * 2 ** (leni - count - 1)
		count += 1
		itr = itr.next
	return numi % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	curr = head
	prev = None
	while curr != None:
		temp = curr.next
		curr.next = prev
		prev = curr
		curr = temp
	i = 0
	ans = 0
	while prev != None:
		ans += prev.data * pow(2, i)
		i += 1
		prev = prev.next
	return ans % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	count = -1
	curr = head
	while curr:
		curr = curr.next
		count = count + 1
	final = 0
	temp = head
	while temp:
		final += (1 << count) * temp.data
		temp = temp.next
		count = count - 1
	return final % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	num = 0
	curr = head
	while curr:
		num = num * 10 + curr.data
		curr = curr.next
	num = int(str(num), 2) % MOD
	return num


def decimalValue(head):
	MOD = 10 ** 9 + 7
	count = 0
	curr1 = head
	while curr1 != None:
		count += 1
		curr1 = curr1.next
	curr = head
	ans = 0
	while curr != None:
		ans = ans + curr.data * 2 ** (count - 1)
		count -= 1
		curr = curr.next
	return ans % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	count = 0
	itr = head
	while itr:
		count += 1
		itr = itr.next
	m = 0
	itr = head
	while itr:
		m += itr.data * 2 ** (count - 1)
		count = count - 1
		itr = itr.next
	return m % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	li = []
	while head:
		li.append(head.data)
		head = head.next
	num = 0
	for i in li:
		num = num * 10 + i
	num = str(num)
	return int(num, 2) % MOD


def decimalValue(head):
	MOD = 10 ** 9 + 7
	res = []
	while head:
		res.insert(0, head.data)
		head = head.next
	dec = 0
	for i in range(len(res)):
		dec += res[i] * 2 ** i
	return dec % MOD