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

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

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

g = A("g")
h = B("h")
f = C("f")
e = A("e")
k = C("k")
c = A("c")

g.q = k
g.x = e
h.t = e
f.u = h
f.t = h
e.q = f
e.x = g
k.u = h
k.t = h
c.q = f
c.x = e
assert k.t.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.x: A = None
        self.txt = txt

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

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

g = A("g")
h = B("h")
f = C("f")
e = A("e")
k = C("k")
c = A("c")

g.q = k
g.x = e
h.t = e
f.u = h
f.t = h
e.q = f
e.x = g
k.u = h
k.t = h
c.q = f
c.x = e
assert k.t.t.q.txt == "f"