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

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

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

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

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

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

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

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

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

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

m.y = h
m.q = f
m.s = e
f.r = m
e.u = h
e.w = h
e.o = m
h.q = m
h.x = f
h.s = e
h.w = e
assert h.q.q.r.txt == "m"