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

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

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

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

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

i.t = j
m.y = k
l.x = m
l.t = g
g.p = l
g.x = l
g.q = l
e.p = l
e.x = l
e.q = l
a.t = j
j.y = a
k.t = m
h.y = i
assert h.y.t.y.t.y.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

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

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

i.t = j
m.y = k
l.x = m
l.t = g
g.p = l
g.x = l
g.q = l
e.p = l
e.x = l
e.q = l
a.t = j
j.y = a
k.t = m
h.y = i
assert h.y.t.y.t.y.t.y.txt == "a"