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.w: A = None
        self.txt = txt

i = A("i")
j = B("j")
h = B("h")
a = A("a")
d = A("d")
c = A("c")

i.z = h
j.y = c
j.w = a
h.y = a
h.w = a
a.z = j
d.z = j
c.z = j
assert d.z.y.z.w.z.y.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.w: A = None
        self.txt = txt

i = A("i")
j = B("j")
h = B("h")
a = A("a")
d = A("d")
c = A("c")

i.z = h
j.y = c
j.w = a
h.y = a
h.w = a
a.z = j
d.z = j
c.z = j
assert d.z.y.z.w.z.y.txt == "c"