class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.s: B = 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.x: A = None
        self.txt = txt

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

f.x = m
f.s = m
m.y = a
a.x = f
assert m.y.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.s: B = 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.x: A = None
        self.txt = txt

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

f.x = m
f.s = m
m.y = a
a.x = f
assert m.y.x.s.txt == "m"