# Sample code of method 1
#!/usr/bin/python3
# -*- coding: utf-8 -*-

#import sys
import string

infile = open('a.in', 'r')
low_ascii = string.ascii_lowercase * 2
high_ascii = string.ascii_uppercase * 2
digit = string.digits * 2

for s in infile:
    if s == '#\n':
        break
    shift_s, text = s.split(':')
    # print(shift_s, text)
    shift_ascii = int(shift_s) % len(string.ascii_lowercase)
    shift_digit = int(shift_s) % len(string.digits)
    
    for ch in text:
        if ch in low_ascii:
            print(low_ascii[low_ascii.index(ch)+shift_ascii], end='')
        elif ch in high_ascii:
            print(high_ascii[high_ascii.index(ch)+shift_ascii], end='')
        elif ch in digit:
            print(digit[digit.index(ch)+shift_digit], end='')
        else:
            print(ch, end='')



# Sample code of method 2
#!/usr/bin/python3
# -*- coding: utf-8 -*-

#import sys
import string

infile = open('a.in', 'r')
low_ascii = string.ascii_lowercase
high_ascii = string.ascii_uppercase
digit = string.digits

for s in infile:
    if s == '#\n':
        break
    shift_s, text = s.split(':')
    shift = int(shift_s)
    
    for ch in text:
        if ch in low_ascii:
            print(low_ascii[(low_ascii.index(ch)+shift) % len(low_ascii)], end='')
        elif ch in high_ascii:
            print(high_ascii[(high_ascii.index(ch)+shift) % len(high_ascii)], end='')
        elif ch in digit:
            print(digit[(digit.index(ch)+shift) % len(digit)], end='')
        else:
            print(ch, end='')



"""
Explanation: UCSY Competitive Programming Training Test-1 (21, Feb, 2018)
Problem-A
Integer before colon shows number of shift, convert text. If shift is 1, A -> B, Z -> A, b -> c, 2 -> 3.
Sample Input
0:Plain Text
1:Heloo Bob
2:My number is 09970693885
27:Heloo Bob
Sample Output
Plain Text
Ifmpp Cpc
Oa pwodgt ku 21192815007
Ifmpp Cpc
How to solve Problem-A
As for text conversion, it's necessary to care of circling such as z to a. There are several methods to handle this.

Create the string which contains ABC...XYZABC....Z
Calculate the (offset(index) of original string + shift) mod sizeof(alphabet or digit)

Method-1 is simpler, Method-2 requires less memory and smarter. Method-1 will be better in programming contest, and Method-2 will be better in production code.
End of explanation
"""


# Method-1

s = '111:Text text 123 text'
shift, text = s.split(':')
print(shift)
print(text)

# Method-2

s = '111:Text text 123 text'
p_col = s.index(':')
print(s[:p_col])
print(s[p_col+1:])

# Method-3

s = '111:Text text 123 text'
p_col = 0
for ch in s:
    if ch == ':':
        break
    p_col += 1
print(s[:p_col])
print(s[p_col+1:])

"""
Explanation: Text handling
In this problem, input text contains shift + ':' + text. There are several methods to treat it.

Use split() method of string (recommended)
Use index() method of string, and separate string using slice (str[start:end])
Search the location of ':' by checking each character in the string, then use slice
End of explanation
"""


s = '   3 space\t(tab)\n'
print(s.strip())
s ='\t(tab)\n 2nd line\n'
print(s.strip())
s ='\n\nNew Line\n\n\n'
print(s.strip())

#!/usr/bin/python3
# -*- coding: utf-8 -*-

#import sys
import string

infile = open('a.in', 'r')
low_ascii = string.ascii_lowercase * 2
high_ascii = string.ascii_uppercase * 2
digit = string.digits * 2

for s in infile:
    if s == '#\n':
        break
    shift_s, text = s.strip().split(':')  # Remove \n before split()
    # print(shift_s, text)
    shift_ascii = int(shift_s) % len(string.ascii_lowercase)
    shift_digit = int(shift_s) % len(string.digits)
    
    for ch in text:
        if ch in low_ascii:
            print(low_ascii[low_ascii.index(ch)+shift_ascii], end='')
        elif ch in high_ascii:
            print(high_ascii[high_ascii.index(ch)+shift_ascii], end='')
        elif ch in digit:
            print(digit[digit.index(ch)+shift_digit], end='')
        else:
            print(ch, end='')
            
    print()   # New line for each output

"""
Explanation: Text handling, new line character
It is necessary to take care of new line('\n'). readline() method returns text which contains '\n' (iterable file object also returns this format of data).
If new line character is to be removed, strip() method removes space tab and new line before and after the text.
End of explanation
"""


#!/usr/bin/python3
# -*- coding: utf-8 -*-

#import sys

infile = open('b.in', 'r')
n = int(infile.readline())
even_num = list()
for i in range(n):
    num = int(infile.readline())
    even_num.append(num)

max_prime = max(even_num)

# Sieve of Eratosthenes
prime_map = [True for i in range(max_prime+1)]
prime_map[0] = prime_map[1] = False  # Not Prime

prime_list = list()
for i in range(2, max_prime+1):
    if prime_map[i] == True:
        prime_list.append(i)
        for mop in range(i*2, max_prime+1, i):
            prime_map[mop] = False

# print(prime_map) # Debug
# print(prime_list) # Debug

# print(even_num)
for i in even_num:
    half = i // 2
    num_combi = 0
    for p in prime_list:
        if p > half:
            break
        if (i-p) in prime_list:
            # print(p, i-p)   # Debug
            num_combi += 1

    print(num_combi)


"""
Explanation: Problem B. Sum of Primes
Input: 1st Line: Number of test Case, 2nd and later Even Number, Output: Number of pairs of Prime number which sum is equal to given even number.
Sample Input
3
18
30
22
Sample Output
2
3
3
End of explanation
"""


#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def twin_prime(min_range, max_range):

    prime_map = [True for i in range(max_range+1)]
    prime_map[0] = prime_map[1] = False  # Not Prime
    
    for i in range(2, max_range+1):  # include max_range
        if prime_map[i] == True:
            for mop in range(i*2, max_range+1, i):
                prime_map[mop] = False
    
    num_twin = 0
    for i in range(min_range, max_range-1):  # include max_range
        if prime_map[i] and prime_map[i+2]:
            print(i, i+2, file=sys.stderr) # Debug
            num_twin += 1

    print(num_twin)

infile = open('c.in', 'r')
n = int(infile.readline())
for i in range(n):
    min_range, max_range = map(int,infile.readline().split())
    twin_prime(min_range, max_range)


"""
Explanation: Problem C. Twin Prime Numbers
Print the number of twin prime number in specific range. Twin Prime number: Both P and P+2 are prime number, for example 3 and 5, 11 and 13.
End of explanation
"""


