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

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

e = A("e")
g = B("g")
a = B("a")
j = A("j")
c = A("c")
d = A("d")
b = B("b")

e.u = c
e.w = j
g.s = a
a.s = b
j.u = e
j.w = d
c.u = j
c.w = d
d.u = c
d.w = j
b.s = g
assert d.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.w: A = None
        self.txt = txt

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

e = A("e")
g = B("g")
a = B("a")
j = A("j")
c = A("c")
d = A("d")
b = B("b")

e.u = c
e.w = j
g.s = a
a.s = b
j.u = e
j.w = d
c.u = j
c.w = d
d.u = c
d.w = j
b.s = g
assert d.w.w.w.txt == "j"