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

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

g = A("g")
f = B("f")
e = B("e")
l = B("l")
m = A("m")

g.t = f
f.x = l
f.w = e
e.x = l
e.w = l
l.x = f
l.w = f
m.t = l
assert e.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

g = A("g")
f = B("f")
e = B("e")
l = B("l")
m = A("m")

g.t = f
f.x = l
f.w = e
e.x = l
e.w = l
l.x = f
l.w = f
m.t = l
assert e.x.x.x.txt == "l"