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

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

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

b = A("b")
d = B("d")
g = C("g")
j = A("j")
a = C("a")
e = C("e")

b.v = j
d.s = j
g.x = d
g.s = e
j.v = b
a.x = d
a.s = g
e.x = d
e.s = a
assert b.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

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

b = A("b")
d = B("d")
g = C("g")
j = A("j")
a = C("a")
e = C("e")

b.v = j
d.s = j
g.x = d
g.s = e
j.v = b
a.x = d
a.s = g
e.x = d
e.s = a
assert b.v.v.v.txt == "j"