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

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

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

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

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

n.p = m
n.q = m
h.o = d
h.y = n
d.p = h
b.y = n
b.r = n
b.w = d
b.q = h
m.y = n
m.r = n
m.w = d
m.q = h
assert h.o.p.y.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.q: D = None
        self.txt = txt

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

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

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

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

n.p = m
n.q = m
h.o = d
h.y = n
d.p = h
b.y = n
b.r = n
b.w = d
b.q = h
m.y = n
m.r = n
m.w = d
m.q = h
assert h.o.p.y.p.w.txt == "d"