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

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

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

d = A("d")
m = B("m")
f = C("f")
l = A("l")
j = C("j")

d.y = l
d.u = m
m.v = d
f.v = j
f.r = j
l.y = d
l.u = m
j.v = f
j.r = f
assert d.u.v.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.u: B = None
        self.txt = txt

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

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

d = A("d")
m = B("m")
f = C("f")
l = A("l")
j = C("j")

d.y = l
d.u = m
m.v = d
f.v = j
f.r = j
l.y = d
l.u = m
j.v = f
j.r = f
assert d.u.v.y.txt == "l"