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

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

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

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

m.x = i
i.y = m
i.t = f
g.s = i
f.x = i
assert g.s.t.x.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

m.x = i
i.y = m
i.t = f
g.s = i
f.x = i
assert g.s.t.x.t.txt == "f"