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

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

d = A("d")
e = B("e")
k = A("k")
b = A("b")
m = B("m")
j = A("j")
a = B("a")

d.x = j
d.q = j
e.v = k
k.x = b
k.q = j
b.x = j
b.q = d
m.v = b
j.x = d
j.q = b
a.v = j
assert m.v.q.q.x.q.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.q: A = None
        self.txt = txt

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

d = A("d")
e = B("e")
k = A("k")
b = A("b")
m = B("m")
j = A("j")
a = B("a")

d.x = j
d.q = j
e.v = k
k.x = b
k.q = j
b.x = j
b.q = d
m.v = b
j.x = d
j.q = b
a.v = j
assert m.v.q.q.x.q.q.x.txt == "j"