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

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

f = A("f")
j = B("j")
e = A("e")
k = A("k")
c = B("c")
h = B("h")
m = B("m")

f.y = k
f.r = h
j.s = f
j.q = e
e.y = f
e.r = c
k.y = e
k.r = h
c.s = e
c.q = k
h.s = e
h.q = e
m.s = e
m.q = k
assert m.q.r.s.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.r: B = None
        self.txt = txt

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

f = A("f")
j = B("j")
e = A("e")
k = A("k")
c = B("c")
h = B("h")
m = B("m")

f.y = k
f.r = h
j.s = f
j.q = e
e.y = f
e.r = c
k.y = e
k.r = h
c.s = e
c.q = k
h.s = e
h.q = e
m.s = e
m.q = k
assert m.q.r.s.r.s.txt == "e"