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

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

j = A("j")
d = B("d")
g = A("g")
e = B("e")
i = B("i")

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

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

j = A("j")
d = B("d")
g = A("g")
e = B("e")
i = B("i")

j.z = d
d.y = j
g.z = d
e.y = j
i.y = g
assert d.y.z.y.z.txt == "d"