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

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

j = A("j")
d = B("d")
k = A("k")
f = B("f")

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

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

j = A("j")
d = B("d")
k = A("k")
f = B("f")

j.u = f
d.z = f
k.u = d
f.z = d
assert j.u.z.z.z.txt == "d"