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

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

c = A("c")
e = B("e")
k = B("k")
d = B("d")
a = A("a")
b = B("b")
i = A("i")
l = B("l")
h = A("h")

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

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

c = A("c")
e = B("e")
k = B("k")
d = B("d")
a = A("a")
b = B("b")
i = A("i")
l = B("l")
h = A("h")

c.r = b
c.x = i
e.q = l
e.v = b
k.q = d
k.v = l
d.q = e
d.v = b
a.r = e
a.x = h
b.q = d
b.v = e
i.r = e
i.x = h
l.q = k
l.v = b
h.r = k
h.x = c
assert a.r.v.q.txt == "d"