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

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

d = A("d")
l = B("l")
h = B("h")
i = B("i")
b = B("b")
j = A("j")
m = B("m")
e = A("e")
c = B("c")

d.q = l
d.r = j
l.v = e
l.p = d
h.v = d
h.p = d
i.v = d
i.p = j
b.v = d
b.p = d
j.q = i
j.r = d
m.v = j
m.p = j
e.q = m
e.r = j
c.v = j
c.p = e
assert i.v.r.r.r.q.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: A = None
        self.txt = txt

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

d = A("d")
l = B("l")
h = B("h")
i = B("i")
b = B("b")
j = A("j")
m = B("m")
e = A("e")
c = B("c")

d.q = l
d.r = j
l.v = e
l.p = d
h.v = d
h.p = d
i.v = d
i.p = j
b.v = d
b.p = d
j.q = i
j.r = d
m.v = j
m.p = j
e.q = m
e.r = j
c.v = j
c.p = e
assert i.v.r.r.r.q.v.q.txt == "l"