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

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

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

d = A("d")
j = B("j")
i = C("i")
f = B("f")
h = B("h")
b = C("b")
g = C("g")

d.t = b
j.u = f
j.v = d
i.x = d
f.u = h
f.v = d
h.u = f
h.v = d
b.x = d
g.x = d
assert d.t.x.t.x.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

d = A("d")
j = B("j")
i = C("i")
f = B("f")
h = B("h")
b = C("b")
g = C("g")

d.t = b
j.u = f
j.v = d
i.x = d
f.u = h
f.v = d
h.u = f
h.v = d
b.x = d
g.x = d
assert d.t.x.t.x.t.x.txt == "d"