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

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

c = A("c")
l = B("l")
g = B("g")
f = B("f")
j = A("j")
h = B("h")
b = B("b")
n = A("n")
i = A("i")
m = B("m")

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

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

c = A("c")
l = B("l")
g = B("g")
f = B("f")
j = A("j")
h = B("h")
b = B("b")
n = A("n")
i = A("i")
m = B("m")

c.u = i
l.p = g
g.p = m
f.p = g
j.u = i
h.p = l
b.p = g
n.u = j
i.u = j
m.p = g
assert b.p.p.p.p.txt == "m"