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

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

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

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

i = A("i")
f = B("f")
a = C("a")
h = D("h")
m = B("m")
j = B("j")

i.u = a
f.v = a
a.u = j
h.u = f
m.v = a
j.v = a
assert a.u.v.u.v.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

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

i = A("i")
f = B("f")
a = C("a")
h = D("h")
m = B("m")
j = B("j")

i.u = a
f.v = a
a.u = j
h.u = f
m.v = a
j.v = a
assert a.u.v.u.v.txt == "a"