#!/usr/bin/python

import sys
import random

t2 = open(sys.argv[1])
cpUsed = int(sys.argv[2])
cpTotal = int(sys.argv[3])

fTest = False
cp = 1
cn = 1

cp2 = cpUsed + 1

rgpUsed = []

#random.seed(0)

while len(rgpUsed) < cpUsed:
    pRandom = random.randint(1,cpTotal)
    if not pRandom in rgpUsed:
        rgpUsed.append(pRandom)

for ln in t2:
    ln = ln.strip()
    if not fTest:
        print ln
        if "case \"$1\" in" in ln:
            fTest = True
    else:
        ln = ln.strip()
        if ln.startswith("*)"):
            fTest = False
        else:
            fp1 = ln.startswith('p')
            iparen = ln.index(")")
            restofln = ln[iparen:]
            if fp1:
                if int(ln[1:iparen]) in rgpUsed:
                    print "p"+str(cp)+restofln
                    cp += 1
                else:
                    print "p"+str(cp2)+restofln
                    cp2 += 1
            else:
                cn += 1
                print ln
    
