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

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

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

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

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

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

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

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

j.q = b
j.s = m
m.w = c
b.t = c
b.q = j
c.t = b
c.q = k
k.q = c
k.s = g
g.w = b
assert g.w.q.q.t.t.q.txt == "j"