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.w: B = None
        self.txt = txt

h = A("h")
l = B("l")
d = B("d")
k = A("k")
b = A("b")
f = B("f")

h.y = f
h.q = l
l.w = f
d.w = l
k.y = f
k.q = f
b.y = l
b.q = d
f.w = d
assert h.q.w.w.w.w.w.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.w: B = None
        self.txt = txt

h = A("h")
l = B("l")
d = B("d")
k = A("k")
b = A("b")
f = B("f")

h.y = f
h.q = l
l.w = f
d.w = l
k.y = f
k.q = f
b.y = l
b.q = d
f.w = d
assert h.q.w.w.w.w.w.txt == "d"