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

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

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

h.o = i
h.y = j
k.q = n
b.o = i
b.y = j
i.q = b
n.o = i
n.y = b
j.o = i
j.y = n
a.q = n
assert a.q.o.q.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.y: A = None
        self.txt = txt

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

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

h.o = i
h.y = j
k.q = n
b.o = i
b.y = j
i.q = b
n.o = i
n.y = b
j.o = i
j.y = n
a.q = n
assert a.q.o.q.y.y.txt == "n"