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

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

g = A("g")
b = B("b")
k = B("k")
h = A("h")
d = A("d")
c = A("c")
j = B("j")
n = B("n")
l = B("l")

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

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

g = A("g")
b = B("b")
k = B("k")
h = A("h")
d = A("d")
c = A("c")
j = B("j")
n = B("n")
l = B("l")

g.x = b
b.t = n
b.q = k
k.t = j
k.q = j
h.x = l
d.x = n
c.x = k
j.t = n
j.q = b
n.t = k
n.q = j
l.t = j
l.q = n
assert d.x.t.q.t.q.q.t.txt == "n"