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

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

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

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

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

a.t = e
j.y = n
n.w = b
f.z = c
f.y = j
f.q = a
c.z = f
c.y = d
c.q = e
e.t = i
i.t = a
b.y = g
d.y = g
g.w = j
assert i.t.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

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

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

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

a.t = e
j.y = n
n.w = b
f.z = c
f.y = j
f.q = a
c.z = f
c.y = d
c.q = e
e.t = i
i.t = a
b.y = g
d.y = g
g.w = j
assert i.t.t.t.t.t.txt == "e"