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

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

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

b = A("b")
j = B("j")
g = C("g")

b.q = j
b.r = g
j.r = g
j.z = g
g.x = b
g.v = j
assert b.r.v.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: C = None
        self.txt = txt

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

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

b = A("b")
j = B("j")
g = C("g")

b.q = j
b.r = g
j.r = g
j.z = g
g.x = b
g.v = j
assert b.r.v.z.txt == "g"