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

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

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

class D:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

m = A("m")
a = B("a")
e = C("e")
h = D("h")

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

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

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

class D:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

m = A("m")
a = B("a")
e = C("e")
h = D("h")

m.o = a
m.r = e
a.r = h
a.w = h
a.y = m
e.s = a
h.w = m
assert m.o.w.w.o.txt == "a"