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

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

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

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

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

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

m.t = n
j.q = m
n.q = l
k.t = h
l.t = f
g.q = k
f.q = l
h.q = k
assert n.q.t.q.t.txt == "f"