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

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

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

g = A("g")
m = B("m")
e = C("e")
i = A("i")

g.w = e
m.p = e
e.t = g
i.w = e
assert m.p.t.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
e = C("e")
i = A("i")

g.w = e
m.p = e
e.t = g
i.w = e
assert m.p.t.w.t.txt == "g"