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

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

c = A("c")
g = B("g")
f = B("f")
m = B("m")

c.w = m
c.z = f
g.r = m
f.r = m
m.r = g
assert c.z.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.z: B = None
        self.txt = txt

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

c = A("c")
g = B("g")
f = B("f")
m = B("m")

c.w = m
c.z = f
g.r = m
f.r = m
m.r = g
assert c.z.r.r.r.txt == "m"