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

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

j = A("j")
f = B("f")
m = A("m")
i = B("i")
a = B("a")
d = A("d")
n = B("n")
b = A("b")
e = A("e")

j.r = f
j.y = a
f.q = d
m.r = a
m.y = a
i.q = b
a.q = d
d.r = f
d.y = n
n.q = j
b.r = a
b.y = f
e.r = a
e.y = f
assert i.q.y.q.r.q.y.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.y: B = None
        self.txt = txt

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

j = A("j")
f = B("f")
m = A("m")
i = B("i")
a = B("a")
d = A("d")
n = B("n")
b = A("b")
e = A("e")

j.r = f
j.y = a
f.q = d
m.r = a
m.y = a
i.q = b
a.q = d
d.r = f
d.y = n
n.q = j
b.r = a
b.y = f
e.r = a
e.y = f
assert i.q.y.q.r.q.y.q.r.txt == "f"