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

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

n = A("n")
f = B("f")
l = A("l")
d = A("d")
b = B("b")
i = A("i")
k = B("k")
h = B("h")

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

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

n = A("n")
f = B("f")
l = A("l")
d = A("d")
b = B("b")
i = A("i")
k = B("k")
h = B("h")

n.t = f
n.q = l
f.q = i
l.t = h
l.q = i
d.t = f
d.q = l
b.q = l
i.t = f
i.q = d
k.q = n
h.q = d
assert h.q.q.q.txt == "i"