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

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

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

c = A("c")
a = B("a")
k = C("k")
n = B("n")
j = A("j")
b = B("b")
d = A("d")
l = A("l")
g = C("g")

c.z = g
c.x = n
a.o = k
a.r = k
a.y = c
k.q = d
n.o = k
n.y = c
n.r = g
j.z = g
j.x = a
b.o = g
b.r = g
b.y = j
d.z = k
d.x = n
l.z = k
l.x = a
g.q = c
assert g.q.z.q.z.q.x.r.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.x: B = None
        self.txt = txt

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

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

c = A("c")
a = B("a")
k = C("k")
n = B("n")
j = A("j")
b = B("b")
d = A("d")
l = A("l")
g = C("g")

c.z = g
c.x = n
a.o = k
a.r = k
a.y = c
k.q = d
n.o = k
n.y = c
n.r = g
j.z = g
j.x = a
b.o = g
b.r = g
b.y = j
d.z = k
d.x = n
l.z = k
l.x = a
g.q = c
assert g.q.z.q.z.q.x.r.q.x.txt == "n"