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

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

d = A("d")
j = B("j")
g = A("g")
m = A("m")
k = A("k")
l = A("l")

d.q = j
d.r = j
j.s = d
j.u = m
g.q = j
g.r = j
m.q = j
m.r = j
k.q = j
k.r = j
l.q = j
l.r = j
assert g.q.u.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: B = None
        self.txt = txt

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

d = A("d")
j = B("j")
g = A("g")
m = A("m")
k = A("k")
l = A("l")

d.q = j
d.r = j
j.s = d
j.u = m
g.q = j
g.r = j
m.q = j
m.r = j
k.q = j
k.r = j
l.q = j
l.r = j
assert g.q.u.q.u.txt == "m"