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

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

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

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

b = A("b")
d = B("d")
a = C("a")
n = D("n")
c = D("c")
j = A("j")
m = A("m")
g = A("g")

b.p = d
b.t = a
d.q = m
d.s = a
a.z = d
n.z = a
n.s = d
c.z = a
c.s = d
j.p = d
j.t = a
m.p = d
m.t = a
g.p = d
g.t = a
assert j.p.s.z.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.t: C = None
        self.txt = txt

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

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

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

b = A("b")
d = B("d")
a = C("a")
n = D("n")
c = D("c")
j = A("j")
m = A("m")
g = A("g")

b.p = d
b.t = a
d.q = m
d.s = a
a.z = d
n.z = a
n.s = d
c.z = a
c.s = d
j.p = d
j.t = a
m.p = d
m.t = a
g.p = d
g.t = a
assert j.p.s.z.s.z.txt == "d"