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

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

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

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

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

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

a.u = j
a.p = k
i.r = h
i.s = d
j.u = k
j.p = k
b.r = i
b.s = e
k.u = a
k.p = j
h.r = e
h.s = b
d.r = n
d.s = b
n.r = e
n.s = h
e.r = i
e.s = h
assert d.r.s.r.r.s.s.s.txt == "e"