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

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

n = A("n")
c = B("c")
a = B("a")
k = A("k")
b = B("b")

n.z = k
n.w = k
c.y = a
c.w = n
a.y = c
a.w = k
k.z = n
k.w = n
b.y = a
b.w = n
assert a.w.z.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.w: A = None
        self.txt = txt

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

n = A("n")
c = B("c")
a = B("a")
k = A("k")
b = B("b")

n.z = k
n.w = k
c.y = a
c.w = n
a.y = c
a.w = k
k.z = n
k.w = n
b.y = a
b.w = n
assert a.w.z.w.txt == "k"