{$apptype console}
// Задача "Ничего и не терялось"
// 8-ая Интернет-олимпиада сезона 2006-2007, базовый уровень
// Автор условия: Федор Царев, tsarev@rain.ifmo.ru
// Автор решения: Максим Буздалов, buzdalov@rain.ifmo.ru

// Использует сортировку на выходе и матрицу отношений для хранения информации.

program giggle_sortout_after;

uses sysutils;

type Tokenizer = object
    data: string;
    pos: integer;
    len: integer;

    constructor create(var s: string);
    function next: string;
end;

constructor Tokenizer.create(var s: string);
begin
    data := s;
    pos := 0;
    len := length(data);
end;

function Tokenizer.next: string;
var
    i: integer;
begin
    i := pos + 1;
    while (i <= len) and (data[i] <> ' ') do inc(i);
    result := copy(data, pos + 1, i - pos - 1);
    pos := i;
end;

var
    kwds:  array [1..2500] of string;
    sites: array [1..2500] of string;
    matrix: array [1..2500, 1..2500] of boolean;
    temp: array[1..2500] of string;

    line, command, keyword, site: string;
    ln: Tokenizer;

    i, j, j1, k: integer;

    n: integer;
    kwdCnt: integer;
    siteCnt: integer;
    cont: boolean;

function findKwd(var s: string): integer;
var
    i: integer;
begin
    result := kwdCnt + 1;
    for i := 1 to kwdCnt do begin
        if kwds[i] = s then begin
            result := i;
            exit;
        end;
    end;
end;

function findSite(var s: string): integer;
var
    i: integer;
begin
    result := siteCnt + 1;
    for i := 1 to siteCnt do begin
        if sites[i] = s then begin
            result := i;
            exit;
        end;
    end;
end;

procedure qsort(start, finish: integer);
var
    left, right: integer;
    mid, tmp: string;
begin
    if start >= finish then exit;
    left := start;
    right := finish;
    mid := temp[(start + finish) div 2];
    while left <= right do begin
        while temp[left] < mid do inc(left);
        while temp[right] > mid do dec(right);
        if left <= right then begin
            tmp := temp[left];
            temp[left] := temp[right];
            temp[right] := tmp;
            inc(left);
            dec(right);
        end;
    end;
    qsort(start, right);
    qsort(left, finish);
end;

begin
    reset(input, 'giggle.in');
    rewrite(output, 'giggle.out');

    readln(n);
    kwdCnt := 0;
    siteCnt := 0;

    for k := 1 to n do begin
        readln(line);
        ln.create(line);
        command := ln.next;
        if command = 'Add' then begin
            ln.next; //keyword
            keyword := ln.next;
            ln.next; //to
            site := ln.next;

            j := findKwd(keyword);
            if j > kwdCnt then begin
                inc(kwdCnt);
                kwds[j] := keyword;
            end;

            j1 := findSite(site);
            if j1 > siteCnt then begin
                inc(siteCnt);
                sites[j1] := site;
            end;

            if matrix[j][j1] then begin
                writeln('Already exists');
            end else begin
                matrix[j][j1] := true;
                writeln('OK');                
            end;
        end else if command = 'Remove' then begin
            ln.next; //keyword
            keyword := ln.next;
            ln.next; //to
            site := ln.next;            

            j := findKwd(keyword);
            j1 := findSite(site);
            if (j > kwdCnt) or (j1 > siteCnt) or not matrix[j][j1] then begin
                writeln('Not found');
            end else begin
                matrix[j][j1] := false;
                writeln('OK');
            end;
        end else if command = 'Search' then begin
            keyword := ln.next;

            j := findKwd(keyword);
            if j > kwdCnt then begin
                writeln('Results: 0 site(s) found');
            end else begin
                j1 := 0;
                for i := 1 to siteCnt do if matrix[j][i] then inc(j1);
                writeln('Results: ', j1, ' site(s) found');
                j1 := 0;
                i := 1;
                while (i <= siteCnt) do begin
                    if matrix[j][i] then begin
                        inc(j1);
                        temp[j1] := sites[i];
                    end;
                    inc(i);    
                end;

                qsort(1, j1);

                i := 1;
                while (i <= 10) and (i <= j1) do begin
                    writeln(i, ') ', temp[i]);
                    inc(i);
                end;
            end;
        end;
        if k <> n then writeln('=====');
    end;
end.
