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

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

j = A("j")
h = B("h")
n = A("n")
a = B("a")
k = A("k")

j.t = n
h.q = a
n.t = j
a.q = h
k.t = j
assert a.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

j = A("j")
h = B("h")
n = A("n")
a = B("a")
k = A("k")

j.t = n
h.q = a
n.t = j
a.q = h
k.t = j
assert a.q.q.q.q.txt == "a"