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

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

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

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

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

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

j.q = k
j.r = c
f.x = m
f.q = k
d.x = f
d.q = l
m.x = d
m.q = l
c.x = d
c.q = k
h.x = f
h.q = k
k.q = l
k.r = c
l.q = j
l.r = h
assert k.r.x.q.q.q.r.x.txt == "d"