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

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

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

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

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

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

a.x = n
n.u = a
c.u = a
assert c.u.x.u.txt == "a"