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

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

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

f = A("f")
c = B("c")
e = C("e")
g = A("g")
k = A("k")

f.t = e
c.v = e
c.p = g
e.w = f
e.q = g
e.p = k
g.t = e
k.t = e
assert g.t.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

f = A("f")
c = B("c")
e = C("e")
g = A("g")
k = A("k")

f.t = e
c.v = e
c.p = g
e.w = f
e.q = g
e.p = k
g.t = e
k.t = e
assert g.t.p.t.txt == "e"