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

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

a = A("a")
c = B("c")
m = A("m")
i = B("i")
b = B("b")

a.p = m
a.u = b
c.w = a
c.u = a
m.p = a
m.u = c
i.w = a
i.u = a
b.w = a
b.u = a
assert c.u.u.u.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.u: B = None
        self.txt = txt

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

a = A("a")
c = B("c")
m = A("m")
i = B("i")
b = B("b")

a.p = m
a.u = b
c.w = a
c.u = a
m.p = a
m.u = c
i.w = a
i.u = a
b.w = a
b.u = a
assert c.u.u.u.p.p.txt == "a"