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

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

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

d = A("d")
f = B("f")
m = C("m")

d.t = m
f.y = m
m.y = d
m.v = d
m.s = d
assert d.t.v.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

d = A("d")
f = B("f")
m = C("m")

d.t = m
f.y = m
m.y = d
m.v = d
m.s = d
assert d.t.v.t.txt == "m"