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

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

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

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

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

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

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

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

j.x = k
j.u = k
g.r = f
g.s = k
k.q = g
f.x = k
f.u = k
assert g.s.q.r.txt == "f"