Quite easy if you closely read the question. My solution is in Python:
Spoiler:
Code:
import sys

def probHeads(n):
  if n == 0:
    return 0
  d = pow(2,n)
  sum = 0
  for x in range(1, n+1):
    sum += d * x / pow(2,x)
  sum += d * x / pow(2,x)

  return sum
  
def solve(n, m):
  solution = probHeads(n) - probHeads(m)
  return solution if solution > 0 else 0

amount = 0
while True:
  line = raw_input()
  if amount == 0:
    limit = line
  else:
    (n,m) = line.split(" ")
    print "%.2f" % solve(n,m)
  amount += 1
  
  if amount == limit:
    sys.exit(0)