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

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

l = A("l")
d = B("d")
j = A("j")
a = A("a")
i = A("i")
e = B("e")
n = B("n")
h = A("h")

l.z = e
d.x = e
d.w = l
j.z = e
a.z = e
i.z = d
e.x = n
e.w = a
n.x = d
n.w = a
h.z = n
assert j.z.w.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

l = A("l")
d = B("d")
j = A("j")
a = A("a")
i = A("i")
e = B("e")
n = B("n")
h = A("h")

l.z = e
d.x = e
d.w = l
j.z = e
a.z = e
i.z = d
e.x = n
e.w = a
n.x = d
n.w = a
h.z = n
assert j.z.w.z.txt == "e"