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

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

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

a = A("a")
n = B("n")
k = C("k")
c = A("c")
i = C("i")
g = A("g")

a.r = c
n.w = g
n.y = g
n.z = k
k.v = i
c.r = g
i.v = k
g.r = a
assert a.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

a = A("a")
n = B("n")
k = C("k")
c = A("c")
i = C("i")
g = A("g")

a.r = c
n.w = g
n.y = g
n.z = k
k.v = i
c.r = g
i.v = k
g.r = a
assert a.r.r.r.txt == "a"