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

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

l = A("l")
e = B("e")
i = B("i")
a = A("a")
d = A("d")
g = B("g")

l.u = i
l.v = g
e.x = g
e.v = i
i.x = e
i.v = g
a.u = g
a.v = e
d.u = e
d.v = i
g.x = i
g.v = e
assert g.x.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.v: B = None
        self.txt = txt

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

l = A("l")
e = B("e")
i = B("i")
a = A("a")
d = A("d")
g = B("g")

l.u = i
l.v = g
e.x = g
e.v = i
i.x = e
i.v = g
a.u = g
a.v = e
d.u = e
d.v = i
g.x = i
g.v = e
assert g.x.x.v.txt == "i"