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

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

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

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

m.y = a
m.x = c
d.w = c
d.t = a
a.x = d
a.s = m
a.r = c
f.x = d
f.s = c
f.r = c
c.y = f
c.x = m
assert m.y.s.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.x: A = None
        self.txt = txt

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

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

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

m.y = a
m.x = c
d.w = c
d.t = a
a.x = d
a.s = m
a.r = c
f.x = d
f.s = c
f.r = c
c.y = f
c.x = m
assert m.y.s.y.r.txt == "c"