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

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

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

i = A("i")
g = B("g")
j = C("j")
a = A("a")
l = B("l")
k = C("k")

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

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

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

i = A("i")
g = B("g")
j = C("j")
a = A("a")
l = B("l")
k = C("k")

i.x = g
i.q = j
g.w = a
g.r = i
j.q = a
a.x = g
a.q = k
l.w = a
l.r = a
k.q = a
assert g.r.x.w.x.txt == "g"