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

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

g = A("g")
f = B("f")
n = A("n")
m = A("m")
i = B("i")
j = A("j")

g.w = i
f.y = i
n.w = f
m.w = i
i.y = f
j.w = i
assert j.w.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

g = A("g")
f = B("f")
n = A("n")
m = A("m")
i = B("i")
j = A("j")

g.w = i
f.y = i
n.w = f
m.w = i
i.y = f
j.w = i
assert j.w.y.y.y.txt == "f"