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

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

d = A("d")
h = B("h")
g = B("g")
c = B("c")
j = B("j")
e = A("e")

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

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

d = A("d")
h = B("h")
g = B("g")
c = B("c")
j = B("j")
e = A("e")

d.u = e
h.s = c
h.u = c
g.s = h
g.u = h
c.s = h
c.u = j
j.s = h
j.u = h
e.u = d
assert h.s.s.u.txt == "c"