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

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

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

m = A("m")
c = B("c")
d = C("d")
k = A("k")
a = C("a")
b = C("b")

m.w = k
c.q = m
d.y = c
d.w = m
k.w = m
a.y = c
a.w = k
b.y = c
b.w = m
assert k.w.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: A = None
        self.txt = txt

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

m = A("m")
c = B("c")
d = C("d")
k = A("k")
a = C("a")
b = C("b")

m.w = k
c.q = m
d.y = c
d.w = m
k.w = m
a.y = c
a.w = k
b.y = c
b.w = m
assert k.w.w.w.w.txt == "k"