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

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

a = A("a")
c = B("c")
k = A("k")
h = B("h")
m = A("m")
i = A("i")
l = B("l")

a.u = k
c.s = k
c.p = k
k.u = a
h.s = k
h.p = a
m.u = i
i.u = m
l.s = k
l.p = a
assert m.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

a = A("a")
c = B("c")
k = A("k")
h = B("h")
m = A("m")
i = A("i")
l = B("l")

a.u = k
c.s = k
c.p = k
k.u = a
h.s = k
h.p = a
m.u = i
i.u = m
l.s = k
l.p = a
assert m.u.u.u.u.u.txt == "i"