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

class B:
    def __init__(self, txt: str):
        self.z: B = None
        self.w: C = 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")
k = C("k")
i = B("i")

f.x = j
f.w = i
f.q = n
n.z = i
n.w = j
j.v = f
k.v = f
i.z = n
i.w = k
assert k.v.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.w: B = None
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.z: B = None
        self.w: C = 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")
k = C("k")
i = B("i")

f.x = j
f.w = i
f.q = n
n.z = i
n.w = j
j.v = f
k.v = f
i.z = n
i.w = k
assert k.v.x.v.txt == "f"