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

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

class C:
    def __init__(self, txt: str):
        self.v: D = None
        self.o: D = None
        self.u: E = None
        self.x: A = None
        self.p: D = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.o: A = None
        self.p: F = None
        self.txt = txt

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

class F:
    def __init__(self, txt: str):
        self.r: E = None
        self.txt = txt

a = A("a")
n = B("n")
b = C("b")
g = D("g")
i = E("i")
k = F("k")
m = E("m")
c = B("c")

a.p = i
n.r = c
n.q = a
b.v = g
b.o = g
b.p = g
b.u = i
b.x = a
g.o = a
g.p = k
i.y = c
i.x = a
k.r = m
m.y = c
m.x = a
c.r = n
c.q = a
assert n.r.r.r.r.r.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: E = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.v: D = None
        self.o: D = None
        self.u: E = None
        self.x: A = None
        self.p: D = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.o: A = None
        self.p: F = None
        self.txt = txt

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

class F:
    def __init__(self, txt: str):
        self.r: E = None
        self.txt = txt

a = A("a")
n = B("n")
b = C("b")
g = D("g")
i = E("i")
k = F("k")
m = E("m")
c = B("c")

a.p = i
n.r = c
n.q = a
b.v = g
b.o = g
b.p = g
b.u = i
b.x = a
g.o = a
g.p = k
i.y = c
i.x = a
k.r = m
m.y = c
m.x = a
c.r = n
c.q = a
assert n.r.r.r.r.r.q.p.txt == "i"