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

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

m = A("m")
n = B("n")
b = B("b")
a = B("a")
l = B("l")
d = A("d")
h = B("h")
j = B("j")
i = A("i")

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

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

m = A("m")
n = B("n")
b = B("b")
a = B("a")
l = B("l")
d = A("d")
h = B("h")
j = B("j")
i = A("i")

m.p = d
n.u = d
b.u = m
a.u = d
l.u = m
d.p = i
h.u = m
j.u = i
i.p = m
assert j.u.p.p.p.p.p.p.p.txt == "m"