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

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

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

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

f.t = a
a.x = f
a.v = i
g.w = i
g.r = f
i.x = f
i.v = a
assert g.r.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

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

f.t = a
a.x = f
a.v = i
g.w = i
g.r = f
i.x = f
i.v = a
assert g.r.t.x.txt == "f"