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

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

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

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

k = A("k")
m = B("m")
b = C("b")
n = D("n")
a = B("a")
d = C("d")
i = B("i")

k.v = a
k.p = n
m.q = n
m.v = n
m.p = i
m.y = i
b.q = i
b.o = a
n.o = d
a.q = n
a.v = n
a.p = i
a.y = i
d.q = m
d.o = m
i.q = n
i.v = n
i.p = a
i.y = m
assert n.o.q.p.p.q.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.p: D = None
        self.txt = txt

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

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

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

k = A("k")
m = B("m")
b = C("b")
n = D("n")
a = B("a")
d = C("d")
i = B("i")

k.v = a
k.p = n
m.q = n
m.v = n
m.p = i
m.y = i
b.q = i
b.o = a
n.o = d
a.q = n
a.v = n
a.p = i
a.y = i
d.q = m
d.o = m
i.q = n
i.v = n
i.p = a
i.y = m
assert n.o.q.p.p.q.o.o.txt == "m"