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

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

b = A("b")
c = B("c")
f = A("f")
h = A("h")
d = B("d")
m = A("m")
a = B("a")
k = B("k")

b.q = k
b.v = c
c.x = d
c.u = f
f.q = d
f.v = a
h.q = c
h.v = a
d.x = c
d.u = h
m.q = k
m.v = k
a.x = c
a.u = h
k.x = a
k.u = h
assert d.x.x.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.v: B = None
        self.txt = txt

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

b = A("b")
c = B("c")
f = A("f")
h = A("h")
d = B("d")
m = A("m")
a = B("a")
k = B("k")

b.q = k
b.v = c
c.x = d
c.u = f
f.q = d
f.v = a
h.q = c
h.v = a
d.x = c
d.u = h
m.q = k
m.v = k
a.x = c
a.u = h
k.x = a
k.u = h
assert d.x.x.u.q.txt == "c"