When users post an update on social media,such as a URL, image, status update etc., other users in their network are able to view this new post on their news feed. Users can also see exactly when the post was published, i.e, how many hours, minutes or seconds ago. 

Since sometimes posts are published and viewed in different time zones, this can be confusing. You are given two timestamps of one such post that a user can see on his newsfeed in the following format: 

Day dd Mon yyyy hh:mm:ss +xxxx

Here +xxxx represents the time zone. Your task is to print the absolute difference (in seconds) between them.  

Input Format

The first line contains $\mathbf{T}$, the number of testcases. 

Each testcase contains $2$ lines, representing time $\boldsymbol{t_1}$ and time $t_2$. 

Constraints

Input contains only valid timestamps
$year\:\leq3000$. 

Output Format

Print the absolute difference $(t_1-t_2)$ in seconds.  

Sample Input 0
2
Sun 10 May 2015 13:54:36 -0700
Sun 10 May 2015 13:54:36 -0000
Sat 02 May 2015 19:54:36 +0530
Fri 01 May 2015 13:54:36 -0000

Sample Output 0
25200
88200

Explanation 0

In the first query, when we compare the time in UTC for both the time stamps, we see a difference of 7 hours. which is $7\times3600$ seconds or $25200$ seconds.  

Similarly, in the second query, time difference is 5 hours and 30 minutes for time zone adjusting for that we have a difference of 1 day and 30 minutes. Or $24\times3600+30\times60\Rightarrow88200$

Difficulty: MEDIUM

Starter code:

Solutions:
from datetime import datetime, timedelta
s = '%a %d %b %Y %H:%M:%S %z'
t = int(input())
for _ in range(t):
	a = datetime.strptime(input(), s)
	b = datetime.strptime(input(), s)
	print(int(abs(timedelta.total_seconds(b - a))))


import datetime
for t in range(0, int(input())):
	d1 = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	d2 = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	if d1 > d2:
		td = d1 - d2
	else:
		td = d2 - d1
	print(td.seconds + 86400 * td.days)


from datetime import datetime
from datetime import timedelta
n = int(input())
time_format = '%a %d %b %Y %H:%M:%S %z'
for _ in range(n):
	a = input()
	b = input()
	at = datetime.strptime(a, time_format)
	bt = datetime.strptime(b, time_format)
	print(int(abs((at - bt).total_seconds())))


import datetime

def call(s):
	p = '-' + s[1]
	if s[2] == 'jan':
		p = '-01' + p
	if s[2] == 'feb':
		p = '-02' + p
	if s[2] == 'mar':
		p = '-03' + p
	if s[2] == 'apr':
		p = '-04' + p
	if s[2] == 'may':
		p = '-05' + p
	if s[2] == 'jun':
		p = '-06' + p
	if s[2] == 'jul':
		p = '-07' + p
	if s[2] == 'aug':
		p = '-08' + p
	if s[2] == 'sep':
		p = '-09' + p
	if s[2] == 'oct':
		p = '-10' + p
	if s[2] == 'nov':
		p = '-11' + p
	if s[2] == 'dec':
		p = '-12' + p
	p = s[3] + p
	p = p + ' ' + s[4]
	return p
n = int(input())
for i in range(n):
	s = input().lower().split()
	s1 = input().lower().split()
	p = call(s)
	q = call(s1)
	a = datetime.datetime.strptime(p, '%Y-%m-%d %H:%M:%S')
	b = datetime.datetime.strptime(q, '%Y-%m-%d %H:%M:%S')
	d = int(s[5])
	if d < 0:
		e = int(abs(d) / 100)
		f = abs(d) % 100
		a = a + datetime.timedelta(0, e * 60 * 60 + f * 60)
	else:
		e = int(abs(d) / 100)
		f = abs(d) % 100
		a = a - datetime.timedelta(0, e * 60 * 60 + f * 60)
	d1 = int(s1[5])
	if d1 < 0:
		e1 = int(abs(d1) / 100)
		f1 = abs(d1) % 100
		b = b + datetime.timedelta(0, e1 * 60 * 60 + f1 * 60)
	else:
		e1 = int(abs(d1) / 100)
		f1 = abs(d1) % 100
		b = b - datetime.timedelta(0, e1 * 60 * 60 + f1 * 60)
	print(abs(int((a - b).total_seconds())))


from datetime import datetime
format = '%a %d %b %Y %H:%M:%S %z'
N = int(input())
for n in range(N):
	t = []
	for i in range(2):
		t.append(datetime.strptime(input(), format))
	print(abs(round((t[0] - t[1]).total_seconds())))


from datetime import datetime
date_fmt = '%a %d %b %Y %H:%M:%S %z'
input_dates = [(input(), input()) for _ in range(int(input()))]
for (t1, t2) in input_dates:
	t1 = datetime.strptime(t1, date_fmt)
	t2 = datetime.strptime(t2, date_fmt)
	print(abs(int((t1 - t2).total_seconds())))


import datetime
t = int(input())
while t:
	t1 = input()
	(t1, tz) = (t1[:-5], t1[-5:])
	(s, h, m) = (tz[0], int(tz[1:3]), int(tz[3:]))
	if s == '+':
		(h, m) = (h * -1, m * -1)
	t1 = datetime.datetime.strptime(t1, '%a %d %b %Y %H:%M:%S ') + datetime.timedelta(hours=h, minutes=m)
	t2 = input()
	(t2, tz) = (t2[:-5], t2[-5:])
	(s, h, m) = (tz[0], int(tz[1:3]), int(tz[3:]))
	if s == '+':
		(h, m) = (h * -1, m * -1)
	t2 = datetime.datetime.strptime(t2, '%a %d %b %Y %H:%M:%S ') + datetime.timedelta(hours=h, minutes=m)
	print(str(abs((t1 - t2).total_seconds())).split('.')[0])
	t = t - 1


from datetime import datetime
from time import time
import sys
n = int(sys.stdin.readline())
fmt = '%a %d %b %Y %H:%M:%S %z'
for _ in range(n):
	x = sys.stdin.readline().strip()
	y = sys.stdin.readline().strip()
	print('%.0f' % abs((datetime.strptime(x, fmt) - datetime.strptime(y, fmt)).total_seconds()))


import datetime
N = int(input())
for n in range(N):
	a = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	b = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(int(abs((b - a).total_seconds())))


from datetime import datetime as dt
N = int(input())
for i in range(N):
	t1 = dt.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t2 = dt.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	if t1 > t2:
		print(int((t1 - t2).total_seconds()))
	else:
		print(int((t2 - t1).total_seconds()))


import datetime
T = int(input())
for i in range(0, T):
	a = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	b = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(abs(round((a - b).total_seconds())))


import datetime
N = int(input())
for i in range(0, N):
	time1 = input()
	time2 = input()
	t1 = datetime.datetime.strptime(time1.rsplit(' ', 1)[0], '%a %d %b %Y %H:%M:%S').timestamp()
	t2 = datetime.datetime.strptime(time2.rsplit(' ', 1)[0], '%a %d %b %Y %H:%M:%S').timestamp()
	a = time1.rsplit(' ', 1)[1]
	b = time2.rsplit(' ', 1)[1]
	if a[0] == '-':
		t1 = t1 + int(a[-4:-2]) * 3600 + int(a[-2:]) * 60
	else:
		t1 = t1 - (int(a[-4:-2]) * 3600 + int(a[-2:]) * 60)
	if b[0] == '-':
		t2 = t2 + int(b[-4:-2]) * 3600 + int(b[-2:]) * 60
	else:
		t2 = t2 - (int(b[-4:-2]) * 3600 + int(b[-2:]) * 60)
	difference = t1 - t2
	if difference < 0:
		difference = -difference
	print(int(difference))


import sys
from datetime import datetime
sys.stdin.readline()
while True:
	operand1 = sys.stdin.readline()
	if not operand1:
		break
	operand2 = sys.stdin.readline()
	date1 = datetime.strptime(operand1.strip(), '%a %d %b %Y %H:%M:%S %z')
	date2 = datetime.strptime(operand2.strip(), '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((date1 - date2).total_seconds())))


from datetime import datetime

def parse_date(date):
	return datetime.strptime(date, '%a %d %b %Y %H:%M:%S %z')
T = int(input())
for _ in range(T):
	(a, b) = (input(), input())
	a = parse_date(a)
	b = parse_date(b)
	diff = abs(int((a - b).total_seconds()))
	print(diff)


from time import strptime
from datetime import datetime
f = lambda s: datetime.strptime(s, '%a %d %b %Y %H:%M:%S %z')
t = int(input())
for _ in range(t):
	x = f(input())
	y = f(input())
	print(int(abs(x - y).total_seconds()))


from datetime import datetime

def days_between(d1, d2):
	d1 = datetime.strptime(d1, '%a %d %b %Y %H:%M:%S %z')
	d2 = datetime.strptime(d2, '%a %d %b %Y %H:%M:%S %z')
	if d1 > d2:
		return getTime(d1 - d2)
	else:
		return getTime(d2 - d1)

def getTime(c):
	return abs(c.days) * 24 * 60 * 60 + abs(c.seconds)
s = input()
for i in range(0, int(s)):
	d1 = input()
	d2 = input()
	s = datetime.strptime(d1, '%a %d %b %Y %H:%M:%S %z')
	d = datetime.strptime(d2, '%a %d %b %Y %H:%M:%S %z')
	print(days_between(d1, d2))


import datetime
N = int(input())
for i in range(N):
	first = input()
	second = input()
	time1 = datetime.datetime.strptime(first, '%a %d %b %Y %H:%M:%S %z')
	time2 = datetime.datetime.strptime(second, '%a %d %b %Y %H:%M:%S %z')
	d = time1 - time2
	print(abs(int(d.total_seconds())))


from datetime import datetime
import sys
fmt = '%a %d %b %Y %H:%M:%S %z'
data = sys.stdin.readlines()[1:]
data = [datetime.strptime(x.strip(), fmt) for x in data]
for (d1, d2) in zip(data[::2], data[1::2]):
	print(int(abs((d1 - d2).total_seconds())))


from datetime import datetime
for k in range(int(input())):
	(a, b) = (datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z') for i in '..')
	print(round(abs((a - b).total_seconds())))


from datetime import *

def main():
	n = int(input())
	for i in range(n):
		time1 = input()
		time2 = input()
		diff1 = datetime.strptime(time1, '%a %d %b %Y %H:%M:%S %z')
		diff2 = datetime.strptime(time2, '%a %d %b %Y %H:%M:%S %z')
		print(abs(round((diff1 - diff2).total_seconds())))
main()


from datetime import datetime
n_tests = int(input())
for _ in range(n_tests):
	first_datetime = datetime.strptime(input().strip(), '%a %d %b %Y %X %z')
	second_datetime = datetime.strptime(input(), '%a %d %b %Y %X %z')
	delta = second_datetime - first_datetime
	print(abs(int(delta.total_seconds())))


T = int(input())
from datetime import datetime
for t in range(T):
	t1 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((t2 - t1).total_seconds())))


import datetime
import sys

def convert(data):
	return datetime.datetime.strptime(data, '%a %d %b %Y %H:%M:%S %z')

def run():
	data = list(sys.stdin)
	data = [convert(v.strip('\n')) for v in data[1:]]
	for i in range(len(data) // 2):
		print(int(abs((data[i * 2] - data[i * 2 + 1]).total_seconds())))
run()


from datetime import datetime, timedelta

def calc_dif(x, y):
	_format1 = '%a %d %b %Y %H:%M:%S %z'
	i = datetime.strptime(x, _format1)
	j = datetime.strptime(y, _format1)
	td = abs(i - j)
	print(td.days * 24 * 60 * 60 + td.seconds)
N = int(input())
for i in range(N):
	a = input()
	b = input()
	calc_dif(a, b)


from datetime import datetime
fmt = '%d %b %Y %H:%M:%S %z'
for _ in range(int(input())):
	t1 = datetime.strptime(input()[4:], fmt)
	t2 = datetime.strptime(input()[4:], fmt)
	print(abs(int((t1 - t2).total_seconds())))


import datetime
T = int(input())
for _ in range(T):
	t1 = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	delta = t1 - t2
	print(abs(delta.days * 3600 * 24 + delta.seconds))


from datetime import datetime

def parse(strng):
	return datetime.strptime(strng, '%a %d %b %Y %H:%M:%S %z')
t = int(input())
for _ in range(t):
	time1 = parse(input())
	time2 = parse(input())
	print(abs(int((time1 - time2).total_seconds())))


import sys
from datetime import datetime
input_rows = sys.stdin.read().split('\n')
(T, input_rows) = (int(input_rows[0]), input_rows[1:])
date_format = '%a %d %b %Y %H:%M:%S %z'
for i in range(0, 2 * T, 2):
	t1 = datetime.strptime(input_rows[i], date_format)
	t2 = datetime.strptime(input_rows[i + 1], date_format)
	timeDelta = t1 - t2
	print(int(abs(timeDelta.total_seconds())))


from datetime import datetime
n = int(input())
i = 0
time = list()
while i < n:
	d1 = input()
	d2 = input()
	time.append((d1, d2))
	i = i + 1
for (d1, d2) in time:
	t1 = datetime.strptime(d1, '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.strptime(d2, '%a %d %b %Y %H:%M:%S %z')
	print(int(abs(t1 - t2).total_seconds()))


from datetime import *
import sys
firstline = input().split()
T = int(firstline[0])
data = sys.stdin.readlines()
for t in range(0, T * 2, 2):
	firstdate = data[t].strip()
	seconddate = data[t + 1].strip()
	date1 = datetime.strptime(firstdate, '%a %d %b %Y %H:%M:%S %z')
	date2 = datetime.strptime(seconddate, '%a %d %b %Y %H:%M:%S %z')
	print('%d' % abs((date2 - date1).total_seconds()))


from datetime import datetime, timedelta
T = int(input())
F = '%a %d %b %Y %H:%M:%S %z'
for _ in range(T):
	s1 = input()
	t1 = datetime.strptime(s1, F)
	s2 = input()
	t2 = datetime.strptime(s2, F)
	t = t1 - t2 if t1 > t2 else t2 - t1
	print(t.seconds + t.days * 3600 * 24)


from datetime import datetime
N = int(input())
for i in range(0, N):
	d1 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	d2 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(int(abs((d1 - d2).total_seconds())))


import time
import datetime as dt
t = int(input())
for i in range(0, t):
	d1 = input()
	d2 = input()
	t1 = dt.datetime.strptime(d1, '%a %d %b %Y %H:%M:%S %z')
	t2 = dt.datetime.strptime(d2, '%a %d %b %Y %H:%M:%S %z')
	dif = t1 - t2
	print(abs(int(dif.total_seconds())))


from datetime import datetime
for _ in range(int(input())):
	start = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	end = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((end - start).total_seconds())))


import sys
import datetime
file = sys.stdin
N = int(file.readline())
for i in range(N):
	ts1 = file.readline().rstrip('\n')
	ts2 = file.readline().rstrip('\n')
	ts_format = '%a %d %b %Y %H:%M:%S %z'
	t1 = datetime.datetime.strptime(ts1, ts_format)
	t2 = datetime.datetime.strptime(ts2, ts_format)
	tdiff = abs(int((t1 - t2).total_seconds()))
	print(tdiff)


from datetime import datetime
import sys
N = int(sys.stdin.readline().strip())
for i in range(N):
	t1 = sys.stdin.readline().strip()
	t2 = sys.stdin.readline().strip()
	t1_obj = datetime.strptime(t1, '%a %d %b %Y %H:%M:%S %z')
	t2_obj = datetime.strptime(t2, '%a %d %b %Y %H:%M:%S %z')
	diff = t1_obj - t2_obj
	print(abs(int(diff.total_seconds())))


import sys
import datetime

def parse_date(s):
	i = s.rfind(' ')
	d = datetime.datetime.strptime(s[:i], '%a %d %b %Y %H:%M:%S')
	h = int(s[i + 2:i + 4])
	m = int(s[i + 4:i + 6])
	delta = datetime.timedelta(hours=h, minutes=m)
	if s[i + 1] == '+':
		return d - delta
	else:
		return d + delta
t = int(sys.stdin.readline())
for k in range(t):
	start = sys.stdin.readline()
	end = sys.stdin.readline()
	delta = parse_date(end) - parse_date(start)
	print(int(abs(delta.total_seconds())))


import datetime
N = int(input())

def todatetime(s):
	date_part = s[4:]
	d = datetime.datetime.strptime(date_part, '%d %b %Y %H:%M:%S %z')
	return d
for n in range(N):
	s1 = input()
	s2 = input()
	td = todatetime(s1) - todatetime(s2)
	diff = td.days * 24 * 3600 + td.seconds
	print(abs(diff))


from datetime import datetime
for x in range(int(input())):
	a = input()
	b = input()
	at = datetime.strptime(a, '%a %d %b %Y %H:%M:%S %z')
	bt = datetime.strptime(b, '%a %d %b %Y %H:%M:%S %z')
	di = abs(at - bt)
	print(di.days * 24 * 3600 + di.seconds)


import datetime
T = int(input())
for t in range(T):
	l = [datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z') for i in range(2)]
	print('%d' % abs((l[0] - l[1]).total_seconds()))


import sys
import datetime

def inp():
	return sys.stdin.readline().rstrip()
cases = int(inp())
for _ in range(cases):
	first = inp()
	second = inp()
	dto1 = datetime.datetime.strptime(first, '%a %d %b %Y %X %z')
	dto2 = datetime.datetime.strptime(second, '%a %d %b %Y %X %z')
	diff = dto1 - dto2
	print(abs(int(diff.total_seconds())))


from datetime import datetime
for i in range(int(input())):
	t1_raw = input()
	t2_raw = input()
	t1 = datetime.strptime(t1_raw, '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.strptime(t2_raw, '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((t2 - t1).total_seconds())))


from datetime import datetime
t = int(input().strip())
for case in range(0, t):
	date1 = datetime.strptime(input(), '%a %d %b %Y %X %z')
	date2 = datetime.strptime(input(), '%a %d %b %Y %X %z')
	res = date1 - date2
	print(abs(int(res.total_seconds())))


from time import gmtime, mktime
from datetime import datetime
n = int(input())
for _ in range(n):
	t1 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((t1 - t2).total_seconds())))


import datetime
cas = int(input())
for t in range(cas):
	timestamp1 = input().strip()
	timestamp2 = input().strip()
	time_format = '%a %d %b %Y %H:%M:%S %z'
	time_second1 = datetime.datetime.strptime(timestamp1, time_format)
	time_second2 = datetime.datetime.strptime(timestamp2, time_format)
	print(int(abs((time_second1 - time_second2).total_seconds())))


import sys
stdin = sys.stdin
n = int(stdin.readline())
import datetime
for i in range(n):
	dt1 = datetime.datetime.strptime(stdin.readline().rstrip(), '%a %d %b %Y %H:%M:%S %z')
	dt2 = datetime.datetime.strptime(stdin.readline().rstrip(), '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((dt2 - dt1).total_seconds())))


import datetime
for i in range(0, int(input())):
	t = input()
	(d1, tz_info1) = (t[:-5], t[-5:])
	(neg, hr, mins) = (tz_info1[0], int(tz_info1[1:3]), int(tz_info1[3:]))
	if neg == '+':
		(hr, mins) = (hr * -1, mins * -1)
	d1 = datetime.datetime.strptime(d1, '%a %d %b %Y %H:%M:%S ')
	d1 = d1 + datetime.timedelta(hours=hr, minutes=mins)
	t = input()
	(d2, tz_info1) = (t[:-5], t[-5:])
	(neg, hr, mins) = (tz_info1[0], int(tz_info1[1:3]), int(tz_info1[3:]))
	if neg == '+':
		(hr, mins) = (hr * -1, mins * -1)
	d2 = datetime.datetime.strptime(d2, '%a %d %b %Y %H:%M:%S ')
	d2 = d2 + datetime.timedelta(hours=hr, minutes=mins)
	diff = abs(d1 - d2)
	print(int(diff.total_seconds()))


from datetime import datetime
T = int(input())
f = '%a %d %b %Y %H:%M:%S %z'
for _ in range(0, T):
	t1 = datetime.strptime(input(), f)
	t2 = datetime.strptime(input(), f)
	d = max(t1, t2) - min(t1, t2)
	print(int(d.total_seconds()))


from datetime import timedelta
from datetime import datetime
for T in range(int(input())):
	t1 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	if t1 == t2:
		print(0)
	elif t1 > t2:
		print(int((t1 - t2).total_seconds()))
	else:
		print(int((t2 - t1).total_seconds()))


from datetime import datetime
FMT = '%a %d %b %Y %H:%M:%S %z'
cases = int(input())
for _ in range(cases):
	d1 = datetime.strptime(input(), FMT)
	d2 = datetime.strptime(input(), FMT)
	delta = d1 - d2
	print(int(abs(delta.total_seconds())))


import sys
from datetime import datetime
n = int(sys.stdin.readline())
for _ in range(n):
	date1 = datetime.strptime(sys.stdin.readline().strip(), '%a %d %b %Y %H:%M:%S %z').timestamp()
	date2 = datetime.strptime(sys.stdin.readline().strip(), '%a %d %b %Y %H:%M:%S %z').timestamp()
	print(abs(int(date1 - date2)))


from datetime import datetime, timedelta
T = int(input())
for _ in range(T):
	d1 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	d2 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((d2 - d1).total_seconds())))


import datetime
cases = int(input())
for tests in range(cases):
	date1_string = input()
	date2_string = input()
	date1 = datetime.datetime.strptime(date1_string, '%a %d %b %Y %H:%M:%S %z')
	date2 = datetime.datetime.strptime(date2_string, '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((date1 - date2).total_seconds())))


from datetime import datetime
fmt = '%a %d %b %Y %H:%M:%S %z'
T = int(input())
for _ in range(T):
	t1 = datetime.strptime(input(), fmt)
	t2 = datetime.strptime(input(), fmt)
	print(abs(int((t1 - t2).total_seconds())))


from datetime import datetime
print
for _ in range(int(input())):
	t1 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((t1 - t2).total_seconds())))


import datetime
t = int(input())
timeFormat = '%a %d %b %Y %H:%M:%S %z'
for i in range(t):
	t1 = datetime.datetime.strptime(input(), timeFormat)
	t2 = datetime.datetime.strptime(input(), timeFormat)
	print(abs(int((t1 - t2).total_seconds())))


from datetime import datetime
import calendar
fmt = '%a %d %b %Y %H:%M:%S %z'
for i in range(int(input())):
	t1 = datetime.strptime(input(), fmt)
	t2 = datetime.strptime(input(), fmt)
	t1 = int(calendar.timegm(t1.utctimetuple()) + t1.microsecond / 1000000.0)
	t2 = int(calendar.timegm(t2.utctimetuple()) + t2.microsecond / 1000000.0)
	print(abs(t1 - t2))


from datetime import datetime
T = int(input())
timestamp_format = '%a %d %b %Y %H:%M:%S %z'
for _ in range(T):
	t1 = datetime.strptime(input(), timestamp_format)
	t2 = datetime.strptime(input(), timestamp_format)
	print(abs(int((t1 - t2).total_seconds())))


import datetime
fmt = '%a %d %b %Y %H:%M:%S %z'
for _ in range(int(input())):
	time1 = datetime.datetime.strptime(input(), fmt)
	time2 = datetime.datetime.strptime(input(), fmt)
	print(abs(int((time1 - time2).total_seconds())))


import sys
from datetime import datetime
n = int(input())
for i in range(n):
	t1 = datetime.strptime(sys.stdin.readline().strip(), '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.strptime(sys.stdin.readline().strip(), '%a %d %b %Y %H:%M:%S %z')
	print(int(abs((t1 - t2).total_seconds())))


from datetime import datetime, timedelta
date_format = '%a %d %b %Y %H:%M:%S %z'
epoch = datetime.utcfromtimestamp(0)
n = int(input())
for i in range(n):
	date1 = datetime.strptime(input(), date_format)
	date1_s = (date1 - epoch.replace(tzinfo=date1.tzinfo)).total_seconds()
	date2 = datetime.strptime(input(), date_format)
	date2_s = (date2 - epoch.replace(tzinfo=date1.tzinfo)).total_seconds()
	print('{0:d}'.format(int(abs(date1_s - date2_s))))


from datetime import timedelta
from datetime import datetime

def findDiff(a, b):
	timeString = '%a %d %b %Y %H:%M:%S %z'
	ta = datetime.strptime(a, timeString)
	tb = datetime.strptime(b, timeString)
	delta = ta - tb
	return int(abs(delta.total_seconds()))
for i in range(0, int(input())):
	print(findDiff(input(), input()))


import datetime
import time

def toSec(x):
	return datetime.timedelta(hours=x.tm_hour, minutes=x.tm_min, seconds=x.tm_sec).total_seconds()
t = input()
for i in range(int(t)):
	a = input()
	b = input()
	a1 = time.strptime(a, '%a %d %b %Y %H:%M:%S %z')
	b1 = time.strptime(b, '%a %d %b %Y %H:%M:%S %z')
	FMT = '%a %d %b %Y %H:%M:%S %z'
	tdelta = datetime.datetime.strptime(a, FMT) - datetime.datetime.strptime(b, FMT)
	print(abs(int(tdelta.total_seconds())))


from datetime import datetime as dt
import calendar as cal
N = int(input())
for _ in range(N):
	s1 = input()
	d1 = dt.strptime(s1, '%a %d %b %Y %H:%M:%S %z')
	s2 = input()
	d2 = dt.strptime(s2, '%a %d %b %Y %H:%M:%S %z')
	print(int(abs((d2 - d1).total_seconds())))


__author__ = 'nongdenchet'
T = input()
T = int(T)
import math
import time
import sys
import datetime
strFormat = '%a %d %b %Y %H:%M:%S %z'

def totimestamp(dt):
	return int(time.mktime(dt.timetuple()) + dt.microsecond / 1000000.0)
for t in range(T):
	first = input()
	second = input()
	f = datetime.datetime.strptime(first, strFormat)
	s = datetime.datetime.strptime(second, strFormat)
	f = f.timestamp()
	s = s.timestamp()
	d = math.fabs(f - s)
	d = int(d)
	sys.stdout.write(str(d) + '\n')


from datetime import datetime, date, time
import time

def time_delta():
	t1 = datetime.strptime(input().strip(), '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.strptime(input().strip(), '%a %d %b %Y %H:%M:%S %z')
	t = abs(t1 - t2)
	print(int(t.total_seconds()))
for i in range(int(input())):
	time_delta()


from datetime import datetime
for t in range(int(input())):
	dt1 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	dt2 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	d = abs(dt1 - dt2)
	print(int(d.total_seconds()))


from datetime import datetime

def get_time(s):
	return datetime.strptime(s, '%a %d %b %Y %H:%M:%S %z')
for _ in range(int(input())):
	a = get_time(input())
	b = get_time(input())
	print(abs(int((b - a).total_seconds())))


from datetime import *
cases = int(input())
time_format = '%a %d %b %Y %H:%M:%S %z'
for i in range(cases):
	in1 = input()
	in2 = input()
	t1 = datetime.strptime(in1, time_format)
	t2 = datetime.strptime(in2, time_format)
	print(abs(int((t1 - t2).total_seconds())))


import fileinput
from datetime import datetime
n = int(input())
for i in range(n):
	line1 = input()
	line2 = input()
	datetime1 = datetime.strptime(line1, '%a %d %b %Y %H:%M:%S %z')
	datetime2 = datetime.strptime(line2, '%a %d %b %Y %H:%M:%S %z')
	diff = int(abs(datetime1 - datetime2).total_seconds())
	print(diff)


import datetime

def main():
	T = int(input())
	for _ in range(T):
		t1 = input()
		t2 = input()
		a = datetime.datetime.strptime(t1, '%a %d %b %Y %H:%M:%S %z')
		b = datetime.datetime.strptime(t2, '%a %d %b %Y %H:%M:%S %z')
		d = abs(a - b)
		sec = d.days * 86400 + d.seconds
		print(sec)
main()


from datetime import *

def main():
	t = int(input())
	for i in range(t):
		t1 = input()
		t2 = input()
		d1 = datetime.strptime(t1, '%a %d %b %Y %H:%M:%S %z')
		d2 = datetime.strptime(t2, '%a %d %b %Y %H:%M:%S %z')
		print(abs(round((d1 - d2).total_seconds())))
main()


import sys
from datetime import datetime as dt
dformat = '%a %d %b %Y %H:%M:%S %z'

def time_delta(t1, t2):
	first = dt.strptime(t1, dformat)
	second = dt.strptime(t2, dformat)
	return int(abs((first - second).total_seconds()))

def __starting_point():
	t = int(input().strip())
	for a0 in range(t):
		t1 = input().strip()
		t2 = input().strip()
		delta = time_delta(t1, t2)
		print(delta)
__starting_point()


from datetime import datetime
for x in range(int(input())):
	t_1 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t_2 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t_3 = abs(t_1 - t_2)
	print(t_3.seconds + t_3.days * 86400)


import sys
import datetime
fmt = '%a %d %b %Y %H:%M:%S %z'
N = int(sys.stdin.readline())
for _ in range(N):
	a = sys.stdin.readline().strip()
	b = sys.stdin.readline().strip()
	ta = datetime.datetime.strptime(a, fmt)
	tb = datetime.datetime.strptime(b, fmt)
	print(int(abs(tb - ta).total_seconds()))


import datetime
format_string = '%a %d %b %Y %H:%M:%S %z'
T = int(input())
for test in range(T):
	t1 = str(input())
	t2 = str(input())
	parsed_t1 = datetime.datetime.strptime(t1, format_string)
	parsed_t2 = datetime.datetime.strptime(t2, format_string)
	diff = parsed_t2 - parsed_t1
	print(int(abs(diff.total_seconds())))


from datetime import datetime
n = 2 * int(input())
for _ in range(0, n, 2):
	a = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	b = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(int(abs((a - b).total_seconds())))


import datetime

def read_time():
	return datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
t = int(input())
for _ in range(t):
	t1 = read_time()
	t2 = read_time()
	print(abs(int((t2 - t1).total_seconds())))


from datetime import datetime
date_format = '%a %d %b %Y %H:%M:%S %z'
t = int(input())
for i in range(t):
	date1 = int(datetime.strptime(input(), date_format).timestamp())
	date2 = int(datetime.strptime(input(), date_format).timestamp())
	print(abs(date1 - date2))


from datetime import datetime as dt
dt_format = '%a %d %b %Y %H:%M:%S %z'
for _ in range(int(input())):
	(ts1, ts2) = (input(), input())
	(dt1, dt2) = (dt.strptime(ts1, dt_format), dt.strptime(ts2, dt_format))
	td = dt2 - dt1
	print(abs(int(td.total_seconds())))


from datetime import timedelta, datetime

def parse(s):
	fmt = '%a %d %b %Y %H:%M:%S %z'
	time = datetime.strptime(s, fmt)
	return time
for i in range(int(input())):
	t1 = parse(input())
	t2 = parse(input())
	ts = t1 - t2
	print(abs(ts.days * 24 * 3600 + ts.seconds))


import datetime
numTests = int(input())
for i in range(numTests):
	t1 = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(abs(int(datetime.timedelta.total_seconds(t1 - t2))))


import datetime
T = int(input())
for t in range(T):
	a = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	b = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((a - b).total_seconds())))


import sys
from datetime import datetime, timezone
from functools import reduce
n = int(sys.stdin.readline())

def parse(x):
	return datetime.strptime(x, '%a %d %b %Y %H:%M:%S %z').astimezone(timezone.utc)
rl = lambda : sys.stdin.readline().strip()
for _ in range(n):
	dt1 = parse(rl())
	dt2 = parse(rl())
	delta = reduce(lambda x, y: y - x, sorted([dt1, dt2]))
	print(int(delta.total_seconds()))


from datetime import datetime

def time_delta(ts1, ts2):
	frmt = '%a %d %b %Y %H:%M:%S %z'
	ts1 = datetime.strptime(ts1, frmt)
	ts2 = datetime.strptime(ts2, frmt)
	return abs((ts1 - ts2).total_seconds())

def main():
	N = int(input())
	for _ in range(N):
		print(int(time_delta(input(), input())))
main()


import datetime
for _ in range(int(input())):
	t1 = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	print(round(abs((t1 - t2).total_seconds())))


from datetime import datetime
import sys
n = int(sys.stdin.readline().split('\n')[0])
for i in range(0, n):
	s1 = sys.stdin.readline().split('\n')[0]
	t1 = datetime.strptime(s1, '%a %d %b %Y %H:%M:%S %z')
	s2 = sys.stdin.readline().split('\n')[0]
	t2 = datetime.strptime(s2, '%a %d %b %Y %H:%M:%S %z')
	tdiff = t2 - t1
	result = tdiff.seconds + tdiff.days * 24 * 3600
	print(abs(result))


from datetime import datetime
import sys
fmt = '%a %d %b %Y %H:%M:%S %z'
n_cases = int(sys.stdin.readline().strip())
for n_case in range(n_cases):
	lines = (sys.stdin.readline().strip() for n in range(2))
	lines = (datetime.strptime(x, fmt) for x in lines)
	(a, b) = lines
	print(abs(int((a - b).total_seconds())))


from datetime import *
n = int(input())
for i in range(n):
	x = input()
	y = input()
	t1 = datetime.strptime(x, '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.strptime(y, '%a %d %b %Y %H:%M:%S %z')
	print(int(abs((t1 - t2).total_seconds())))


import datetime as dt
n = int(input())
for i in range(0, n):
	end_time = input()
	start_time = input()
	start_t = dt.datetime.strptime(start_time, '%a %d %b %Y %H:%M:%S %z')
	end_t = dt.datetime.strptime(end_time, '%a %d %b %Y %H:%M:%S %z')
	print(abs(round((end_t - start_t).total_seconds())))


from datetime import datetime
for _ in range(int(input())):
	start = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	end = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	diff = (end - start).total_seconds()
	print(abs(int(diff)))


from datetime import datetime
N = int(input())
for i in range(0, N):
	t1 = input().split()
	t2 = input().split()
	t1 = t1[1] + '/' + t1[2] + '/' + t1[3] + ' ' + t1[4] + ' ' + t1[5]
	t2 = t2[1] + '/' + t2[2] + '/' + t2[3] + ' ' + t2[4] + ' ' + t2[5]
	d = datetime.strptime(t1, '%d/%b/%Y %H:%M:%S %z')
	d1 = datetime.strptime(t2, '%d/%b/%Y %H:%M:%S %z')
	print(int(abs((d - d1).total_seconds())))


from datetime import datetime
for t in range(int(input())):
	(s1, s2) = (input(), input())
	tz1 = -1 * int(s1[-5:-2]) * 3600 + -1 * int(s1[-5:-4] + s1[-2:]) * 60
	tz2 = -1 * int(s2[-5:-2]) * 3600 + -1 * int(s2[-5:-4] + s2[-2:]) * 60
	d1 = datetime.strptime(s1[:-6], '%a %d %b %Y %H:%M:%S')
	d2 = datetime.strptime(s2[:-6], '%a %d %b %Y %H:%M:%S')
	dt1 = tz1 + (d1 - datetime(1970, 1, 1)).total_seconds()
	dt2 = tz2 + (d2 - datetime(1970, 1, 1)).total_seconds()
	print('{0:.0f}'.format(abs(dt1 - dt2)))


import datetime
tests = int(input())
for idx in range(0, tests):
	start = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	end = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	delta = end - start
	print(int(abs(delta.total_seconds())))


from datetime import datetime

def main():
	fmt = '%a %d %b %Y %H:%M:%S %z'
	t = input()
	t = int(t)
	for i in range(t):
		t1 = input()
		t2 = input()
		a = datetime.strptime(t1, fmt)
		b = datetime.strptime(t2, fmt)
		c = a - b
		print(abs(int(c.total_seconds())))
main()


from datetime import datetime
t = int(input())
for _ in range(t):
	s1 = input()
	s2 = input()
	t1 = datetime.strptime(s1, '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.strptime(s2, '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((t1 - t2).total_seconds())))


import datetime
T = int(input())
for i in range(T):
	t1 = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t2 = datetime.datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	if t1 > t2:
		print(int((t1 - t2).total_seconds()))
	else:
		print(int((t2 - t1).total_seconds()))


from datetime import datetime, date, time
n = int(input())
for i in range(n):
	d1 = input()
	d2 = input()
	x1 = datetime.strptime(d1, '%a %d %b %Y %H:%M:%S %z')
	x2 = datetime.strptime(d2, '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((x1 - x2).total_seconds())))


from datetime import datetime

def solve(t1, t2):
	date_format = '%a %d %b %Y %H:%M:%S %z'
	date1 = datetime.strptime(t1, date_format)
	date2 = datetime.strptime(t2, date_format)
	return int(abs((date2 - date1).total_seconds()))

def main():
	for __ in range(int(input())):
		print(solve(input(), input()))
main()


from datetime import datetime
T = int(input())
for t in range(T):
	d1 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	d2 = datetime.strptime(input(), '%a %d %b %Y %H:%M:%S %z')
	t = d1 - d2
	print(abs(int(t.total_seconds())))


from datetime import datetime, timedelta
N = int(input())
for _ in range(N):
	date1 = input()
	date2 = input()
	date1 = datetime.strptime(date1, '%a %d %b %Y %H:%M:%S %z')
	date2 = datetime.strptime(date2, '%a %d %b %Y %H:%M:%S %z')
	print(abs(int((date1 - date2).total_seconds())))