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

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

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

c = A("c")
a = B("a")
m = C("m")
h = A("h")

c.r = m
c.w = h
c.x = a
a.o = h
m.y = a
h.r = m
h.w = c
h.x = a
assert a.o.x.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.w: A = None
        self.x: B = None
        self.txt = txt

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

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

c = A("c")
a = B("a")
m = C("m")
h = A("h")

c.r = m
c.w = h
c.x = a
a.o = h
m.y = a
h.r = m
h.w = c
h.x = a
assert a.o.x.o.r.txt == "m"