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.s: B = None
        self.txt = txt

a = A("a")
b = B("b")
e = A("e")
n = A("n")
f = B("f")
k = B("k")
h = A("h")

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

a = A("a")
b = B("b")
e = A("e")
n = A("n")
f = B("f")
k = B("k")
h = A("h")

a.q = k
b.t = n
b.s = f
e.q = b
n.q = k
f.t = n
f.s = b
k.t = n
k.s = f
h.q = k
assert k.s.s.s.txt == "f"