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

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

j = A("j")
i = B("i")
k = B("k")
d = B("d")
a = A("a")
e = B("e")

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

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

j = A("j")
i = B("i")
k = B("k")
d = B("d")
a = A("a")
e = B("e")

j.y = a
i.w = e
i.z = d
k.w = e
k.z = i
d.w = k
d.z = k
a.y = j
e.w = k
e.z = i
assert e.z.w.z.txt == "i"