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

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

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

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

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

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

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