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

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

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

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

m = A("m")
h = B("h")
e = C("e")
c = D("c")
j = C("j")
g = A("g")
d = A("d")
n = B("n")

m.z = g
h.o = c
h.q = n
e.v = j
c.p = h
c.r = e
j.v = e
g.z = d
d.z = g
n.o = c
n.q = h
assert g.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

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

m = A("m")
h = B("h")
e = C("e")
c = D("c")
j = C("j")
g = A("g")
d = A("d")
n = B("n")

m.z = g
h.o = c
h.q = n
e.v = j
c.p = h
c.r = e
j.v = e
g.z = d
d.z = g
n.o = c
n.q = h
assert g.z.z.z.z.z.z.txt == "g"