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

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

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

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

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

a.w = h
a.q = n
a.v = m
h.o = m
h.s = m
h.q = a
n.s = h
n.t = h
n.r = m
m.r = a
m.s = h
assert n.s.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.q: C = None
        self.v: D = None
        self.txt = txt

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

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

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

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

a.w = h
a.q = n
a.v = m
h.o = m
h.s = m
h.q = a
n.s = h
n.t = h
n.r = m
m.r = a
m.s = h
assert n.s.s.r.txt == "a"