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

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

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

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

e.q = j
e.o = a
k.w = a
k.s = j
k.z = e
j.v = m
j.p = e
m.v = j
m.p = e
g.v = m
g.p = a
a.q = g
a.o = e
assert j.v.v.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.o: A = None
        self.txt = txt

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

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

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

e.q = j
e.o = a
k.w = a
k.s = j
k.z = e
j.v = m
j.p = e
m.v = j
m.p = e
g.v = m
g.p = a
a.q = g
a.o = e
assert j.v.v.p.q.txt == "j"