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

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

k = A("k")
a = B("a")
e = A("e")
g = B("g")

k.s = a
a.r = g
a.v = g
e.s = a
g.r = a
g.v = a
assert k.s.v.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

k = A("k")
a = B("a")
e = A("e")
g = B("g")

k.s = a
a.r = g
a.v = g
e.s = a
g.r = a
g.v = a
assert k.s.v.r.v.txt == "g"