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

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

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

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

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

d.v = m
j.y = m
j.p = d
j.w = d
j.t = h
n.p = f
n.w = f
n.q = h
n.u = m
m.t = j
m.y = n
h.y = m
h.p = d
h.w = d
h.t = j
f.p = n
f.w = n
f.q = h
f.u = m
assert m.y.q.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

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

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

d.v = m
j.y = m
j.p = d
j.w = d
j.t = h
n.p = f
n.w = f
n.q = h
n.u = m
m.t = j
m.y = n
h.y = m
h.p = d
h.w = d
h.t = j
f.p = n
f.w = n
f.q = h
f.u = m
assert m.y.q.t.p.txt == "d"