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

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

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

m = A("m")
h = B("h")
b = C("b")
k = C("k")
j = C("j")
f = B("f")

m.y = h
h.x = j
h.q = f
b.w = m
k.w = m
j.w = m
f.x = j
f.q = h
assert h.x.w.y.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

m = A("m")
h = B("h")
b = C("b")
k = C("k")
j = C("j")
f = B("f")

m.y = h
h.x = j
h.q = f
b.w = m
k.w = m
j.w = m
f.x = j
f.q = h
assert h.x.w.y.q.q.txt == "h"