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

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

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

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

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

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

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