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

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

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

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

i = A("i")
e = B("e")
d = C("d")
j = D("j")
h = A("h")
c = A("c")
m = A("m")
g = B("g")

i.q = h
e.w = d
d.t = g
d.p = j
j.r = m
h.q = m
c.q = i
m.q = h
g.w = d
assert c.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

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

i = A("i")
e = B("e")
d = C("d")
j = D("j")
h = A("h")
c = A("c")
m = A("m")
g = B("g")

i.q = h
e.w = d
d.t = g
d.p = j
j.r = m
h.q = m
c.q = i
m.q = h
g.w = d
assert c.q.q.q.q.q.q.txt == "h"