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

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

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

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

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

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

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

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

f.s = m
f.p = j
f.q = g
j.q = m
j.t = f
g.q = j
g.o = j
k.q = j
k.o = j
m.s = f
m.p = j
m.q = k
assert j.t.q.q.txt == "j"