#### 189. Perl-like Substr

time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard input
output: standard output

A small Russian offshore company H&H decided to strike the world community and develop their own analogue (faster and with lots of features) of a well-known scripting language Perl. You are hired to participate in this project and your task is very simple - to code the function substr.
Function substr writes and reads separate substrings:
value = substr(string, offset, count);
value = substr(string, offset);
substr(
string, offset, count) = newstring;
substr(
string, offset) = newstring;
string(symbol in Perl marks a scalar variable, the strings in Perl are scalar variables) contains the initial string. offsetdefinesthebeginningofthesubstring.Positivevaluesofoffset are counted out from the beginning of the string, negative - from the end. If the offsetequalstozero, thesubstringbeginsfromthefirstsymbolofstring.Thethirdargumentcount defines the length of the substring. If countisomitted, substrreturnseverythingtotheendofthestring.Ifcount is negative, substr leaves that many characters off the end of the string.
Function substr can be used not only to get the substring from the string, but also to replace the substring with the new string. In the last case the lengths of the old substring and the new one can be different.
You are given a simple Perl-like program (refer to the input and output specifications) and your task is to output the result of its execution.

Input
The first line contains two natural numbers N (1<=N<=20) - the number of initialization lines in the program and M (1<=M<=300) - the number of remaining lines in the program. Next N lines (no one more than 10000 symbols) contain the string initialization in the following form:
name = "value";
name is the name of the string variable (always starts with symbol ).Thenameofthevariableconsistsofupto20(includingsymbol) alfa-numerical letters (and the inthebeginning).Thenameofthevariableisfollowedbysymbol" = ", andthenfollowsthevalueofthevariable - asequenceofalfa - numericalsymbolsandthepunctuators(space, comma, dot, hyphen, underline, colon, exclamationandquestionmarks)enclosedindoublequotes.Thelengthofthevalueisnotmorethan255symbols.Thenameofthevariable, symbol" = ", andthevaluecanbedelimitedbyoneormorespaces.Thereisalwaysasemicolonattheendoftheline.
EachofthefollowingMlinescontainsthelineoftheprograminoneofthefollowing6types:
1. print(
name); Output the value of variable name
2. print(substr(
name, o[, c])); Output the substring from variable name
3.
name1 = name2; Assignthevalueofvariablename1 to the value of variable name2
4.
name1 = substr(name2, o[, c]); Assignthevalueofvariablename1 to the substring from variable name2
5. substr(
name1, o[, c]) = name2; Replacethesubstringinname1with the value of name2
6. substr(
name1, o[, c]) = substr(name2, o[, c]); Replacethesubstringinname1 with the substring from name2

Thesquarebracketsindicatethatthethirdargumentinsubstrcanbeomitted.Theremaybenospacesinsidethenamesofthevariablesandthenamesoffunctions, buttheremaybeoneorseveralspacesinallotherplaces.Thereissymbol";"attheendofeachline, thelengthofeachlineisnotmorethan255symbols.Thevaluesofthevariableswhichweren'tinitializedinthefirstNlinesoftheinputfileareconsideredasemptystrings"".Thetotalnumberofdifferentvariablesintheprogramisnotmorethan100.Novariablevaluewillhavethelengthofmorethan1000symbolsinthecourseoftheprogramexecution.
Theparameters
c and ohavebeenchosenso, thatthesubstrreturnsthe"correct"substring, i.e.thebeginningandtheendofthesubstringarewithintheinitialstring, andthebeginningproceedstheend(substringisnotempty).
Youmustassumethatnamesofvariablesarecasesensitive.

Output
Sampletest(s)
Input
29
a = "0123456789";
b = "abcdefghigklmn";
print(a);
print( substr(b, 1, 2));
substr(b, 0, 1) = substr(a, 2, 7);
c = b;
print(substr(c,0));
print(substr(a,  - 2,  - 1));
print(substr(a, -6, 2));
print(substr(a,  - 5));
print(substr(a, 1, 2));
Output0123456789
bc
2345678bcdefghigklmn
8
45
56789
12
Author:Ilya V. Elterman
Resource:ACM International Collegiate Programming Contest 2003-2004
North-Eastern European Region, Southern Subregion
Date:2003 October, 9