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

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

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

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

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

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

n.r = h
j.q = n
h.q = a
a.r = e
e.q = a
assert h.q.r.q.r.q.txt == "a"