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

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

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

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

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

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

l.p = m
k.q = n
k.r = d
c.r = f
c.x = e
n.w = g
n.r = g
i.o = d
i.x = c
i.t = e
i.s = e
f.p = m
d.p = m
m.q = g
m.r = f
g.w = n
g.r = n
e.o = l
e.x = c
e.t = i
e.s = i
assert k.q.w.r.r.r.w.r.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

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

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

l.p = m
k.q = n
k.r = d
c.r = f
c.x = e
n.w = g
n.r = g
i.o = d
i.x = c
i.t = e
i.s = e
f.p = m
d.p = m
m.q = g
m.r = f
g.w = n
g.r = n
e.o = l
e.x = c
e.t = i
e.s = i
assert k.q.w.r.r.r.w.r.r.w.r.txt == "g"