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

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

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

f = A("f")
n = B("n")
j = C("j")

f.q = n
n.x = j
n.y = f
j.v = f
assert j.v.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

f = A("f")
n = B("n")
j = C("j")

f.q = n
n.x = j
n.y = f
j.v = f
assert j.v.q.x.txt == "j"