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

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

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

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

h = A("h")
k = B("k")
g = C("g")
n = D("n")
i = D("i")
l = B("l")

h.o = k
k.z = h
k.y = g
g.s = k
g.t = i
n.o = g
n.p = h
i.o = g
i.p = h
l.z = h
l.y = g
assert g.t.o.t.o.t.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

h = A("h")
k = B("k")
g = C("g")
n = D("n")
i = D("i")
l = B("l")

h.o = k
k.z = h
k.y = g
g.s = k
g.t = i
n.o = g
n.p = h
i.o = g
i.p = h
l.z = h
l.y = g
assert g.t.o.t.o.t.o.txt == "g"