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

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

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

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

h = A("h")
e = B("e")
m = C("m")
j = D("j")
i = B("i")
n = D("n")
g = A("g")
k = C("k")
b = D("b")

h.x = i
e.y = g
m.u = h
j.t = n
i.y = g
n.t = b
g.x = i
k.u = h
b.t = n
assert g.x.y.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

h = A("h")
e = B("e")
m = C("m")
j = D("j")
i = B("i")
n = D("n")
g = A("g")
k = C("k")
b = D("b")

h.x = i
e.y = g
m.u = h
j.t = n
i.y = g
n.t = b
g.x = i
k.u = h
b.t = n
assert g.x.y.x.y.txt == "g"