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

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

a = A("a")
n = B("n")
d = B("d")
j = A("j")
m = A("m")
l = B("l")
g = B("g")
e = B("e")
k = B("k")
f = A("f")

a.v = f
a.q = f
n.u = m
d.u = j
j.v = a
j.q = f
m.v = a
m.q = f
l.u = m
g.u = j
e.u = a
k.u = m
f.v = a
f.q = m
assert l.u.v.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.q: A = None
        self.txt = txt

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

a = A("a")
n = B("n")
d = B("d")
j = A("j")
m = A("m")
l = B("l")
g = B("g")
e = B("e")
k = B("k")
f = A("f")

a.v = f
a.q = f
n.u = m
d.u = j
j.v = a
j.q = f
m.v = a
m.q = f
l.u = m
g.u = j
e.u = a
k.u = m
f.v = a
f.q = m
assert l.u.v.q.q.q.txt == "f"