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

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

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

f = A("f")
g = B("g")
h = C("h")
a = A("a")
k = C("k")

f.x = k
g.w = a
g.q = a
g.y = k
h.x = a
h.q = a
a.x = k
k.x = a
k.q = a
assert h.q.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

f = A("f")
g = B("g")
h = C("h")
a = A("a")
k = C("k")

f.x = k
g.w = a
g.q = a
g.y = k
h.x = a
h.q = a
a.x = k
k.x = a
k.q = a
assert h.q.x.x.txt == "a"