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

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

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

k = A("k")
m = B("m")
l = C("l")
h = A("h")

k.q = h
k.s = m
m.o = l
l.w = h
h.q = k
h.s = m
assert l.w.s.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.s: B = None
        self.txt = txt

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

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

k = A("k")
m = B("m")
l = C("l")
h = A("h")

k.q = h
k.s = m
m.o = l
l.w = h
h.q = k
h.s = m
assert l.w.s.o.w.txt == "h"