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

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

c = A("c")
i = B("i")
m = B("m")
a = A("a")
h = B("h")
j = A("j")
f = B("f")

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

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

c = A("c")
i = B("i")
m = B("m")
a = A("a")
h = B("h")
j = A("j")
f = B("f")

c.y = i
c.q = m
i.v = f
m.v = h
a.y = m
a.q = i
h.v = i
j.y = i
j.q = f
f.v = h
assert c.q.v.v.v.v.v.v.txt == "f"