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

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

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

f.u = j
f.z = j
c.z = f
j.u = f
j.z = f
assert c.z.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.z: A = None
        self.txt = txt

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

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

f.u = j
f.z = j
c.z = f
j.u = f
j.z = f
assert c.z.u.u.txt == "f"