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

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

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

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

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

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

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

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

a.w = g
a.y = f
g.w = f
g.p = a
f.q = k
i.w = f
i.p = a
k.w = f
k.p = a
assert i.w.q.w.txt == "f"