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

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

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

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

n = A("n")
c = B("c")
h = C("h")
d = D("d")
m = A("m")

n.o = d
n.q = h
n.r = m
c.r = m
c.s = h
c.z = d
h.p = n
h.v = c
d.t = c
d.p = c
m.o = d
m.q = h
m.r = n
assert m.r.o.t.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.q: C = None
        self.r: A = None
        self.txt = txt

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

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

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

n = A("n")
c = B("c")
h = C("h")
d = D("d")
m = A("m")

n.o = d
n.q = h
n.r = m
c.r = m
c.s = h
c.z = d
h.p = n
h.v = c
d.t = c
d.p = c
m.o = d
m.q = h
m.r = n
assert m.r.o.t.s.p.txt == "n"