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

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

d = A("d")
k = B("k")
c = A("c")
h = A("h")
j = A("j")
n = B("n")
b = B("b")
l = B("l")

d.w = n
k.z = c
c.w = n
h.w = n
j.w = k
n.z = c
b.z = j
l.z = j
assert n.z.w.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

d = A("d")
k = B("k")
c = A("c")
h = A("h")
j = A("j")
n = B("n")
b = B("b")
l = B("l")

d.w = n
k.z = c
c.w = n
h.w = n
j.w = k
n.z = c
b.z = j
l.z = j
assert n.z.w.z.txt == "c"