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

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

i = A("i")
g = B("g")
f = B("f")
d = B("d")
l = B("l")

i.y = f
g.u = l
g.z = i
f.u = g
f.z = i
d.u = f
d.z = i
l.u = g
l.z = i
assert i.y.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

i = A("i")
g = B("g")
f = B("f")
d = B("d")
l = B("l")

i.y = f
g.u = l
g.z = i
f.u = g
f.z = i
d.u = f
d.z = i
l.u = g
l.z = i
assert i.y.z.y.txt == "f"