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

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

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

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

l = A("l")
a = B("a")
m = C("m")
e = D("e")
i = A("i")
k = D("k")
g = B("g")

l.s = g
a.t = g
m.p = e
e.z = m
e.q = m
e.r = m
i.s = g
k.z = m
k.q = m
k.r = m
g.t = a
assert a.t.t.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

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

l = A("l")
a = B("a")
m = C("m")
e = D("e")
i = A("i")
k = D("k")
g = B("g")

l.s = g
a.t = g
m.p = e
e.z = m
e.q = m
e.r = m
i.s = g
k.z = m
k.q = m
k.r = m
g.t = a
assert a.t.t.t.t.t.t.txt == "a"