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

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

c = A("c")
n = B("n")
a = A("a")
b = B("b")
k = B("k")
f = B("f")
g = B("g")
i = B("i")
m = A("m")
d = A("d")

c.s = g
c.t = m
n.q = b
a.s = n
a.t = m
b.q = k
k.q = n
f.q = i
g.q = b
i.q = n
m.s = f
m.t = d
d.s = n
d.t = a
assert k.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.t: A = None
        self.txt = txt

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

c = A("c")
n = B("n")
a = A("a")
b = B("b")
k = B("k")
f = B("f")
g = B("g")
i = B("i")
m = A("m")
d = A("d")

c.s = g
c.t = m
n.q = b
a.s = n
a.t = m
b.q = k
k.q = n
f.q = i
g.q = b
i.q = n
m.s = f
m.t = d
d.s = n
d.t = a
assert k.q.q.q.txt == "k"