class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: B = None
        self.q: B = None
        self.txt = txt

d = A("d")
n = B("n")
h = A("h")
b = A("b")
f = A("f")
k = B("k")
i = A("i")
e = A("e")
a = A("a")

d.r = n
d.p = k
n.r = k
n.q = k
h.r = n
h.p = k
b.r = k
b.p = n
f.r = n
f.p = k
k.r = n
k.q = n
i.r = k
i.p = n
e.r = n
e.p = k
a.r = k
a.p = k
assert b.r.q.r.q.q.r.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: B = None
        self.q: B = None
        self.txt = txt

d = A("d")
n = B("n")
h = A("h")
b = A("b")
f = A("f")
k = B("k")
i = A("i")
e = A("e")
a = A("a")

d.r = n
d.p = k
n.r = k
n.q = k
h.r = n
h.p = k
b.r = k
b.p = n
f.r = n
f.p = k
k.r = n
k.q = n
i.r = k
i.p = n
e.r = n
e.p = k
a.r = k
a.p = k
assert b.r.q.r.q.q.r.r.q.txt == "n"