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

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

i = A("i")
h = B("h")
b = B("b")
g = A("g")
n = B("n")
f = A("f")

i.w = g
i.u = f
h.v = f
h.s = i
b.v = i
b.s = i
g.w = f
g.u = f
n.v = f
n.s = g
f.w = g
f.u = g
assert i.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.u: A = None
        self.txt = txt

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

i = A("i")
h = B("h")
b = B("b")
g = A("g")
n = B("n")
f = A("f")

i.w = g
i.u = f
h.v = f
h.s = i
b.v = i
b.s = i
g.w = f
g.u = f
n.v = f
n.s = g
f.w = g
f.u = g
assert i.w.w.w.w.txt == "f"