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

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

n = A("n")
k = B("k")
a = B("a")
d = A("d")

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

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

n = A("n")
k = B("k")
a = B("a")
d = A("d")

n.w = d
k.q = a
k.y = n
a.q = k
a.y = d
d.w = n
assert k.y.w.w.w.txt == "d"