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

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

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

m = A("m")
l = B("l")
i = C("i")
k = B("k")
g = C("g")
a = C("a")
j = A("j")

m.q = g
m.y = j
l.x = k
l.s = k
l.p = m
i.v = l
i.r = a
k.x = l
k.s = l
k.p = m
g.v = l
g.r = a
a.v = k
a.r = g
j.q = i
j.y = m
assert g.v.p.q.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.y: A = None
        self.txt = txt

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

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

m = A("m")
l = B("l")
i = C("i")
k = B("k")
g = C("g")
a = C("a")
j = A("j")

m.q = g
m.y = j
l.x = k
l.s = k
l.p = m
i.v = l
i.r = a
k.x = l
k.s = l
k.p = m
g.v = l
g.r = a
a.v = k
a.r = g
j.q = i
j.y = m
assert g.v.p.q.r.v.txt == "k"