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

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

class C:
    def __init__(self, txt: str):
        self.z: C = None
        self.x: D = None
        self.q: D = None
        self.txt = txt

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

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

n.o = b
n.q = h
h.s = b
h.o = b
g.z = d
g.x = b
g.q = f
b.t = d
b.p = h
f.t = d
f.p = h
d.z = g
d.x = f
d.q = b
assert n.o.t.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.q: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.z: C = None
        self.x: D = None
        self.q: D = None
        self.txt = txt

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

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

n.o = b
n.q = h
h.s = b
h.o = b
g.z = d
g.x = b
g.q = f
b.t = d
b.p = h
f.t = d
f.p = h
d.z = g
d.x = f
d.q = b
assert n.o.t.z.z.txt == "d"