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

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

m = A("m")
i = B("i")
b = A("b")
j = B("j")
g = A("g")
c = A("c")
d = A("d")
k = B("k")

m.y = b
i.q = j
i.z = b
b.y = c
j.q = k
j.z = m
g.y = c
c.y = m
d.y = m
k.q = j
k.z = m
assert g.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

m = A("m")
i = B("i")
b = A("b")
j = B("j")
g = A("g")
c = A("c")
d = A("d")
k = B("k")

m.y = b
i.q = j
i.z = b
b.y = c
j.q = k
j.z = m
g.y = c
c.y = m
d.y = m
k.q = j
k.z = m
assert g.y.y.y.y.y.y.txt == "b"