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

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

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

l = A("l")
k = B("k")
d = C("d")
m = A("m")
j = C("j")
h = A("h")
g = C("g")
c = C("c")

l.x = d
k.v = j
k.x = m
k.r = m
d.x = c
m.x = c
j.x = g
h.x = g
g.x = d
c.x = j
assert j.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

l = A("l")
k = B("k")
d = C("d")
m = A("m")
j = C("j")
h = A("h")
g = C("g")
c = C("c")

l.x = d
k.v = j
k.x = m
k.r = m
d.x = c
m.x = c
j.x = g
h.x = g
g.x = d
c.x = j
assert j.x.x.x.txt == "c"