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

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

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

k = A("k")
j = B("j")
m = C("m")
a = B("a")

k.o = j
k.u = a
j.q = k
j.w = k
j.r = m
m.s = k
a.q = k
a.w = k
a.r = m
assert j.r.s.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.u: B = None
        self.txt = txt

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

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

k = A("k")
j = B("j")
m = C("m")
a = B("a")

k.o = j
k.u = a
j.q = k
j.w = k
j.r = m
m.s = k
a.q = k
a.w = k
a.r = m
assert j.r.s.o.txt == "j"