I wrote this little program in pascal:
program split;
var s,p,q,r,t:longint;
a: array of string;
x,y:string;
begin
read (s);
setlength (a,s);
read (p);
readln (a[0]);
for q:=1 to s-1 do
a[q]:=a[0];
for q:=1 to p do
begin
read (x);
if x='SPLIT' then
begin
read (r);
x:=a[r - 1];
read (y);
for t:=0 to r-2 do
if a[t]=a[r - 1] then a[t]:=y;
read (y);
for t:=r-2 to s do
if a[t]=a[r - 1] then a[t]:=y;
end;
if x='QUERY' then
begin
read (t);
writeln (a[t]);
end;
end;
end.

and it wont even go to the loop, it just ends. Can you help?