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

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

a = A("a")
c = B("c")
n = A("n")
b = A("b")

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

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

a = A("a")
c = B("c")
n = A("n")
b = A("b")

a.u = c
c.w = n
n.u = c
b.u = c
assert n.u.w.u.txt == "c"