Start: Nov, 12, 2017 10:00:00
2017秋Python程序设计基础培训第三次作业
End: Nov, 19, 2017 12:00:00
Time elapsed:
Time remaining:

Problem_ID: G
Result: Accepted
Time: 87ms
Memory: 24436kB
Author: zzzhanghc
In contest: 1123

def data(n):
    a=[0 for i in range(24)]
    for i in range(n):
        x,y=map(int,input().split())
        for j in range(x,y+1):
            a[j]=1
    return a
t=int(input())
for k in range(t):
    a,b=map(int,input().split())
    m,n=data(a),data(b)
    sum=0
    for i in range(24):
        if m[i]==1 and n[i]==1:
            sum+=1
    print(sum)