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

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

h = A("h")
a = B("a")
k = B("k")
j = A("j")
b = B("b")
f = B("f")
g = B("g")

h.q = a
a.t = k
a.q = g
k.t = g
k.q = a
j.q = b
b.t = f
b.q = k
f.t = a
f.q = b
g.t = a
g.q = b
assert a.t.t.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: B = None
        self.q: B = None
        self.txt = txt

h = A("h")
a = B("a")
k = B("k")
j = A("j")
b = B("b")
f = B("f")
g = B("g")

h.q = a
a.t = k
a.q = g
k.t = g
k.q = a
j.q = b
b.t = f
b.q = k
f.t = a
f.q = b
g.t = a
g.q = b
assert a.t.t.t.txt == "a"