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

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

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

i = A("i")
d = B("d")
c = C("c")
a = B("a")
b = C("b")

i.x = c
i.r = a
d.z = c
d.x = i
d.w = i
c.v = i
c.x = b
c.s = a
a.z = c
a.x = i
a.w = i
b.v = i
b.x = c
b.s = d
assert i.r.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.r: B = None
        self.txt = txt

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

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

i = A("i")
d = B("d")
c = C("c")
a = B("a")
b = C("b")

i.x = c
i.r = a
d.z = c
d.x = i
d.w = i
c.v = i
c.x = b
c.s = a
a.z = c
a.x = i
a.w = i
b.v = i
b.x = c
b.s = d
assert i.r.w.x.txt == "c"