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

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

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

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

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

g.p = i
g.v = d
i.w = n
b.s = m
b.z = g
b.o = d
d.r = n
d.t = g
d.z = g
n.r = d
n.t = g
n.z = g
m.s = b
m.z = g
m.o = n
assert d.r.r.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.v: D = None
        self.txt = txt

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

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

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

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

g.p = i
g.v = d
i.w = n
b.s = m
b.z = g
b.o = d
d.r = n
d.t = g
d.z = g
n.r = d
n.t = g
n.z = g
m.s = b
m.z = g
m.o = n
assert d.r.r.z.p.txt == "i"