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

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

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

k = A("k")
c = B("c")
g = C("g")
b = A("b")
e = C("e")

k.q = c
k.t = c
k.x = b
c.q = b
c.r = k
g.w = c
g.v = c
g.u = b
b.q = c
b.t = c
b.x = k
e.w = c
e.v = c
e.u = b
assert b.t.q.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.x: A = None
        self.t: B = None
        self.txt = txt

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

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

k = A("k")
c = B("c")
g = C("g")
b = A("b")
e = C("e")

k.q = c
k.t = c
k.x = b
c.q = b
c.r = k
g.w = c
g.v = c
g.u = b
b.q = c
b.t = c
b.x = k
e.w = c
e.v = c
e.u = b
assert b.t.q.t.r.txt == "k"