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

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

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

j = A("j")
d = B("d")
g = C("g")
m = A("m")
c = B("c")
f = B("f")

j.u = m
d.r = f
d.s = g
d.u = g
g.v = j
m.u = j
c.r = f
c.s = g
c.u = g
f.r = c
f.s = g
f.u = g
assert d.s.v.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

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

j = A("j")
d = B("d")
g = C("g")
m = A("m")
c = B("c")
f = B("f")

j.u = m
d.r = f
d.s = g
d.u = g
g.v = j
m.u = j
c.r = f
c.s = g
c.u = g
f.r = c
f.s = g
f.u = g
assert d.s.v.u.u.u.txt == "m"