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

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

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

k = A("k")
g = B("g")
h = C("h")
n = A("n")

k.q = g
k.s = n
g.r = h
g.p = h
g.t = k
h.o = g
n.q = g
n.s = k
assert h.o.t.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: A = None
        self.txt = txt

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

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

k = A("k")
g = B("g")
h = C("h")
n = A("n")

k.q = g
k.s = n
g.r = h
g.p = h
g.t = k
h.o = g
n.q = g
n.s = k
assert h.o.t.s.q.txt == "g"