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

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

f = A("f")
j = B("j")
k = B("k")
l = A("l")
h = A("h")
g = A("g")
a = A("a")
e = B("e")

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

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

f = A("f")
j = B("j")
k = B("k")
l = A("l")
h = A("h")
g = A("g")
a = A("a")
e = B("e")

f.r = e
f.q = j
j.r = f
k.r = l
l.r = e
l.q = k
h.r = e
h.q = j
g.r = j
g.q = e
a.r = j
a.q = k
e.r = f
assert e.r.r.r.q.r.txt == "f"