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

n = A("n")
f = B("f")
j = B("j")

n.x = j
f.u = n
j.u = n
assert j.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

n = A("n")
f = B("f")
j = B("j")

n.x = j
f.u = n
j.u = n
assert j.u.x.u.txt == "n"