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

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

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

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

d = A("d")
g = B("g")
c = C("c")
a = D("a")
i = C("i")
k = B("k")
b = A("b")
j = D("j")
e = D("e")

d.r = j
g.x = k
g.s = b
c.p = i
c.z = j
c.q = k
a.t = j
i.p = c
i.z = a
i.q = g
k.x = g
k.s = b
b.r = j
j.t = e
e.t = j
assert e.t.t.t.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

d = A("d")
g = B("g")
c = C("c")
a = D("a")
i = C("i")
k = B("k")
b = A("b")
j = D("j")
e = D("e")

d.r = j
g.x = k
g.s = b
c.p = i
c.z = j
c.q = k
a.t = j
i.p = c
i.z = a
i.q = g
k.x = g
k.s = b
b.r = j
j.t = e
e.t = j
assert e.t.t.t.t.t.t.t.txt == "j"