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

e = A("e")
n = B("n")
j = B("j")
f = A("f")
m = A("m")
h = A("h")

e.r = n
n.q = m
j.q = m
f.r = n
m.r = n
h.r = n
assert j.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

e = A("e")
n = B("n")
j = B("j")
f = A("f")
m = A("m")
h = A("h")

e.r = n
n.q = m
j.q = m
f.r = n
m.r = n
h.r = n
assert j.q.r.q.txt == "m"