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

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

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

j = A("j")
l = B("l")
a = C("a")
k = B("k")

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

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

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

j = A("j")
l = B("l")
a = C("a")
k = B("k")

j.v = a
l.q = a
l.s = j
a.p = j
a.w = l
a.v = k
k.q = a
k.s = j
assert l.q.v.q.txt == "a"