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

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

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

e = A("e")
n = B("n")
c = C("c")
j = B("j")
k = C("k")
m = C("m")
f = C("f")
d = A("d")
l = A("l")
g = A("g")

e.s = c
e.x = l
n.t = j
n.q = k
n.v = d
c.q = f
c.t = f
j.t = n
j.q = c
j.v = g
k.q = m
k.t = m
m.q = k
m.t = f
f.q = m
f.t = c
d.s = k
d.x = g
l.s = m
l.x = e
g.s = f
g.x = d
assert m.q.t.t.q.t.t.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.x: A = None
        self.txt = txt

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

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

e = A("e")
n = B("n")
c = C("c")
j = B("j")
k = C("k")
m = C("m")
f = C("f")
d = A("d")
l = A("l")
g = A("g")

e.s = c
e.x = l
n.t = j
n.q = k
n.v = d
c.q = f
c.t = f
j.t = n
j.q = c
j.v = g
k.q = m
k.t = m
m.q = k
m.t = f
f.q = m
f.t = c
d.s = k
d.x = g
l.s = m
l.x = e
g.s = f
g.x = d
assert m.q.t.t.q.t.t.t.q.t.txt == "f"