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

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

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

g = A("g")
f = B("f")
j = C("j")
i = A("i")

g.x = i
g.u = j
f.x = g
f.r = g
f.w = j
j.q = f
j.w = f
i.x = g
i.u = j
assert i.x.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.u: C = None
        self.txt = txt

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

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

g = A("g")
f = B("f")
j = C("j")
i = A("i")

g.x = i
g.u = j
f.x = g
f.r = g
f.w = j
j.q = f
j.w = f
i.x = g
i.u = j
assert i.x.u.w.txt == "f"