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

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

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

g = A("g")
m = B("m")
j = C("j")
k = A("k")
c = B("c")

g.s = m
m.o = j
m.s = j
j.q = g
k.s = m
c.o = j
c.s = j
assert k.s.o.q.s.o.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
j = C("j")
k = A("k")
c = B("c")

g.s = m
m.o = j
m.s = j
j.q = g
k.s = m
c.o = j
c.s = j
assert k.s.o.q.s.o.txt == "j"