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

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

k = A("k")
d = B("d")
m = A("m")
i = B("i")
b = A("b")
g = B("g")
f = A("f")

k.x = f
d.v = b
d.r = f
m.x = f
i.v = f
i.r = m
b.x = f
g.v = b
g.r = k
f.x = b
assert m.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

k = A("k")
d = B("d")
m = A("m")
i = B("i")
b = A("b")
g = B("g")
f = A("f")

k.x = f
d.v = b
d.r = f
m.x = f
i.v = f
i.r = m
b.x = f
g.v = b
g.r = k
f.x = b
assert m.x.x.x.txt == "f"