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

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

m = A("m")
f = B("f")
g = B("g")
j = B("j")
n = A("n")
d = B("d")
a = A("a")

m.r = g
m.u = g
f.q = n
f.w = n
g.q = m
g.w = n
j.q = a
j.w = n
n.r = j
n.u = g
d.q = a
d.w = a
a.r = d
a.u = f
assert g.q.r.q.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: B = None
        self.txt = txt

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

m = A("m")
f = B("f")
g = B("g")
j = B("j")
n = A("n")
d = B("d")
a = A("a")

m.r = g
m.u = g
f.q = n
f.w = n
g.q = m
g.w = n
j.q = a
j.w = n
n.r = j
n.u = g
d.q = a
d.w = a
a.r = d
a.u = f
assert g.q.r.q.r.w.r.txt == "j"