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

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

f = A("f")
d = B("d")
b = B("b")
h = A("h")

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

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

f = A("f")
d = B("d")
b = B("b")
h = A("h")

f.u = d
f.z = h
d.s = b
b.s = d
h.u = d
h.z = f
assert h.z.u.s.s.txt == "d"