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

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

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

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

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

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

b.q = m
d.v = c
d.y = a
a.v = m
a.y = f
m.q = c
j.v = m
j.y = a
k.q = b
e.q = m
c.q = m
h.v = k
h.y = j
f.v = k
f.y = j
assert b.q.q.q.q.q.q.q.q.q.q.txt == "c"