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

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

h = A("h")
m = B("m")
j = A("j")
k = B("k")
n = B("n")
f = A("f")
i = A("i")

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

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

h = A("h")
m = B("m")
j = A("j")
k = B("k")
n = B("n")
f = A("f")
i = A("i")

h.u = n
h.q = i
m.t = h
j.u = k
j.q = f
k.t = h
n.t = f
f.u = m
f.q = j
i.u = n
i.q = f
assert j.u.t.u.t.q.q.txt == "f"