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

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

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

f.y = d
f.r = d
m.p = d
m.x = d
g.y = d
g.r = d
d.p = m
d.x = m
assert m.x.x.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.r: B = None
        self.txt = txt

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

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

f.y = d
f.r = d
m.p = d
m.x = d
g.y = d
g.r = d
d.p = m
d.x = m
assert m.x.x.x.p.txt == "m"